10

I'm getting a really weird behavior from the new Duplicate Catcher in Salesforce. It seems like sometimes, the standard Duplicate Catcher will catch duplicate when doing a bulk operation, but some other times, it won't.

Here's an example where it works (same email, blocking operation if dupe):

Account account1 = new Account(
  Name = 'Sample Company',
  Email__c = '[email protected]',
  BillingCountry = 'JP'
);

Account account2 = new Account(
  Name = 'Some Different Company',
  Email__c = '[email protected]',
  BillingCountry = 'JP'
);

insert new Account[]{account1,account2};

Here's an example where it doesn't work (same name - using fuzzy, blocking operation if dupe):

Account account1 = new Account(
    Name = 'Sample Company',
    Email__c = '[email protected]',
    BillingCountry = 'JP'
);

Account account2 = new Account(
    Name = 'Sample Company',
    Email__c = '[email protected]',
    BillingCountry = 'JP'
);

insert new Account[]{account1,account2};

The first scenario seems to work at all time. If I bulkify, add one single record or anything else, it will return an error and prevent from saving - on the UI, Anonymous Apex or through the API.

However, the second scenario doesn't work on bulkify - it will allow users to create dupe records where the name is the same. If I try to do it in two seperate DML requests, the Duplicate Management tool will notify me and prevent from saving, whatever way I used to create that record.


Here's the configuration:

enter image description here

enter image description here

enter image description here

enter image description here


I looked at the documentation and I didn't see any limitation related to that. Have you experienced something alike?


EDIT

It seems like the field was set to unique. Considering this, my conclusion is that duplicate management rules are ignoring duplicate records inside the same transaction.

0

2 Answers 2

1

@jpmonette You are right. From the doc "Things to Know About Duplicate Rules"

Timing of Saves If multiple records are saved simultaneously and your duplicate rule is set to block or alert sales reps, those records aren’t compared with each other. They’re compared only with records already in Salesforce. This behavior doesn't affect the Report option, and duplicate record sets do include records that match other records saved simultaneously.

0

I do not know if this is going to help but you could use some Apex before insert to check for it yourself. I use this function to get the duplicates:

public static List<SObject> checkForDuplicates(List<Contact> contacts){
    List<sObject> duplicateRecords = new List<sObject>();
    Datacloud.FindDuplicatesResult[] results = Datacloud.FindDuplicates.findDuplicates(contacts);
    for(Datacloud.FindDuplicatesResult findDupeResult : results){
        for(Datacloud.DuplicateResult dupeResult : findDupeResult.getDuplicateResults()){
            for(Datacloud.MatchResult matchResult : dupeResult.getMatchResults()){
                for(Datacloud.MatchRecord matchRecord : matchResult.getMatchRecords()){
                    duplicateRecords.add(matchRecord.getRecord());
                }
            }
        }
    }
    return duplicateRecords;
}

You must log in to answer this question.

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