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?
one of these
getRecord=Account:{BillingAddress=null, Id=0013C00000aAyicQAC,

1 Answer 1

  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">
    <label>Account Compact Layout</label>


  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 .