1

I am using the below code to find the duplicate contact using the duplicate rules setup in the org :

Need Suggestion, as to how to find the relation between the payload and matched contacts array. Like which matched duplicate responded to which contact from the list of contact passed.

Datacloud.FindDuplicatesResult[] results = Datacloud.FindDuplicates.findDuplicates(ConList);

Is there a way I can get the index of contact for which the duplicate rule has given the results?? Is there out of the box any option available??

Also, in case I pass the list of contact in for loop and individually get the results and store it then for each contact my all duplicates rule in the org will run that much time. Afraid will cause the CPU time limit to exceed the governor limit.

Is there a better way to compare the contact list to get the matched duplicate record. So, that I can modify the results SAME, NULL, and DIFFERENT based on my requirement.

private static List<AB_Response> checkDuplication(List<Contact> ConList) {
        List<AB_Response> testResponse = new List<CIAM_Response>();
        Map<Id,List<Datacloud.FieldDiff>> duplicateMap = new Map<Id,List<Datacloud.FieldDiff>>();                 
        if (ConList != null && !ConList.isEmpty()) {
            Datacloud.FindDuplicatesResult[] results = Datacloud.FindDuplicates.findDuplicates(ConList);   
            for (Datacloud.FindDuplicatesResult findDupeResult : results) {
                for (Datacloud.DuplicateResult dupeResult : findDupeResult.getDuplicateResults()) {                 
                    for (Datacloud.MatchResult matchResult : dupeResult.getMatchResults()) {        
                        for (Datacloud.MatchRecord matchRecord : matchResult.getMatchRecords()) {                          
                            dupMap.put(matchRecord.getRecord().Id,matchRecord.getFieldDiffs());
                        }
                    }
                }
            }
            }
             List<Contact> duplicateContacts = getDuplicateContacts(dupMap.keySet());             
             for (Contact con: duplicateContacts) {
                testResponse.add(getMessage(con,dupMap.get(con.Id)));
        }        
        return testResponse;
    }

Any suggestions would be much appreciated!!!

2
  • Please don't tag people who aren't interacting with this question. – David Reed Aug 21 '20 at 18:01
  • I was able to do this. Hence closing this thread. – Riya23 Aug 24 '20 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.