4

I'm wondering if I can use the duplicate management rules to find duplicate account/Lead records but if the provided (via API) record does not have a duplicate, then I don't want to insert a record.

eg. I'm getting data for customer's Firstname, Lastname, phone, company, age, and zip.

The lead object in salesforce has a duplicate management rule setup to find duplicates based on Firstname, Lastname, and Zip.

I want to use duplicate management rules against my data to see if any duplicate records exist or not without inserting a lead record if no duplicate record found. In short use duplicate management rules without DML operation.

Because with my data, I'm creating a record for a different Object (let's call it object START) where it has a lookup to Lead. And during duplicate validation for Lead records, if I found the duplicate record, I would create sobject for START and populate lead lookup based on duplicate record found or leave it null if not found.)

In short, I want to use duplicate management rules on Lead to check if duplicate records exist or not without actually inserting Lead records.

0

2 Answers 2

5

There's a FindDuplicates Class that can be used for this exact use case:

Performs rule-based searches for duplicate records. The input is an array of sObjects. Each sObject represents a record you want to find duplicates of. The output identifies the detected duplicates for each input sObject based on active duplicate rules for the given object.

Example:

Account acct = new Account();
acct.Name = 'Acme';
acct.BillingStreet = '123 Fake St';
acct.BillingCity = 'Springfield';
acct.BillingState = 'VT';
acct.BillingCountry = 'US';
        
List<Account> acctList = new List<Account>();
acctList.add(acct); 
 
if (Datacloud.FindDuplicates.findDuplicates(acctList).size() ​== 0) {
// If the new account doesn't have duplicates, insert it.
    insert(acct);
}
2
  • nice one raul!! Jan 8, 2021 at 6:50
  • Thank you guys.
    – Watson
    Jan 8, 2021 at 12:19
1

you could use setSavePoint , check, and rollback. See https://developer.salesforce.com/forums/?id=9060G0000005TUkQAM

0

You must log in to answer this question.

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