2

I have a requirement to find duplicates based on the company name matching against the account name for all the accounts when a lead will be pushed into sfdc.

So I have set up the below logic:

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

But it's checking with all the duplicate rules on the lead object. So, I need some help on the below ones.

  1. Is there a way to run findDuplicates() to match with a specific duplicate rule(i know we can run a for loop and filter the match results. But is there any way to do it directly)
  2. Currently returned records from the duplicate results contain's the company name, Id. So, is there a way to include custom fields in the getRecord() list?
(Datacloud.MatchResult[getEntityType=Contact;getErrors=();getMatchEngine=FuzzyMatchEngine;getMatchRecords=();getRule=Standard_Contact_Match_Rule_v1_1;getSize=0;isSuccess=true;],
Datacloud.MatchResult[getEntityType=Lead;getErrors=();getMatchEngine=ExactMatchEngine;getMatchRecords=();getRule=Custom_Matching_Rule_On_Lead;getSize=0;isSuccess=true;]);isAllowSave=false;],
Datacloud.DuplicateResult[getDuplicateRule=Account_Name_Match;getDuplicateRuleEntityType=Lead;getErrorMessage=Use
one of these
records?;getMatchResults=(Datacloud.MatchResult[getEntityType=Account;getErrors=();getMatchEngine=FuzzyMatchEngine;
getMatchRecords=(Datacloud.MatchRecord[getAdditionalInformation=();getFieldDiffs=(Datacloud.FieldDiff[getDifference=Different;getName=Name;]);getMatchConfidence=100.0;
getRecord=Account:{BillingAddress=null, Id=0013C00000aAyicQAC,
Name=Disney
Inc.};]);getRule=Account_Name_Match;getSize=1;isSuccess=true;]);isAllowSave=false;]);getErrors=();isSuccess=true;])

1 Answer 1

2
  1. No, you should manually process the returned List<Datacloud.FindDuplicatesResult> results:
Datacloud.FindDuplicatesResult[] results = Datacloud.FindDuplicates.findDuplicates(...);
for (Datacloud.FindDuplicatesResult findDupeResult : results) {
    for (Datacloud.DuplicateResult dupeResult : findDupeResult.getDuplicateResults()) {
        if (dupeResult.getDuplicateRule() == 'Target Duplicate Rule Developer Name')) {
            // Process the specific Rule
        }
    }
}
  1. To manage displayed fields of the matchedRecords record list you can set up them in the Primary CompactLayout, considering limitations:
<!--force-app/main/default/objects/Account/compactLayouts/Account_Compact_Layout.compactLayout-meta.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<CompactLayout xmlns="http://soap.sforce.com/2006/04/metadata">
    <fullName>Account_Compact_Layout</fullName>
    <fields>CustomField__c</fields>
    <label>Account Compact Layout</label>
</CompactLayout>

Effect:

[{
  duplicateResults: [{
      // ...
      duplicateRuleEntityType: 'Account',
      matchResults: [{
        // ...
        entityType: 'Account',
        matchRecords: [{
          // ...
          record: {
            // ...
            Id: '...',
            CustomField__c: '...',
          },
        }, ],
      }, ],
    },
    // ...
  ],
  // ...
}, ];

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .