Skip to content

Instantly share code, notes, and snippets.

@Szandor72
Forked from goravseth/findDupes
Created Oct 25, 2017
Embed
What would you like to do?
invocable apex to find duplicate contacts using the new findDuplicates apex stuff
public class Flow_FindDupes {
//https://developer.salesforce.com/forums/?id=906F0000000AzDeIAK
@InvocableMethod(label='Get Dupes' description='Returns something')
public static List<Contact> getDuplicateContacts(List<Contact> contacts) {
system.debug('contacts size = ' + contacts.size());
list<sObject> dasContacts = new list<sobject>();
dasContacts.addall((List<sObject>)(contacts));
list<Contact> duplicateContacts = new list<Contact>();
Datacloud.FindDuplicatesResult[] results = Datacloud.FindDuplicates.findDuplicates(dasContacts);
if(results.size() > 0){
for (Datacloud.FindDuplicatesResult findDupeResult : results) {
for (Datacloud.DuplicateResult dupeResult : findDupeResult.getDuplicateResults()) {
for (Datacloud.MatchResult matchResult : dupeResult.getMatchResults()) {
for (Datacloud.MatchRecord matchRecord : matchResult.getMatchRecords()) {
System.debug('Duplicate Record: ' + matchRecord.getRecord());
contact c = (Contact) matchRecord.getRecord();
duplicateContacts.add(c);
}
}
}
}
}
return duplicateContacts;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment