Friday, 2 April 2021

How to save a record that’s been identified as a duplicate.

 Hi,

Here we are going to learn how to save a record that's identified as duplicate with the help of DMLOptions.

Especially it helps to bypass duplicate rules in test class.

Eg:

Save an account record that’s been identified as a duplicate\

Database.DMLOptions dml = new Database.DMLOptions(); 

dml.DuplicateRuleHeader.allowSave = true;

dml.DuplicateRuleHeader.runAsCurrentUser = true;

Account duplicateAccount = new Account(Name='dupe');

Database.SaveResult sr = Database.insert(duplicateAccount, dml);

if (sr.isSuccess()) {

System.debug('Duplicate account has been inserted in Salesforce!');

}


Reference:

Click for more information

No comments:

Post a Comment

What’s the difference between Einstein Article Recommendations and Suggested Articles?

How Does Einstein Article Recommendations Work? Einstein Article Recommendations helps support agents resolve customer cases efficiently by ...