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

How to include a screen flow in a Lightning Web Component

 Hi, Assume  you have a flow called "Quick Contact Creation" and API Name for the same is "Quick_Contact_Creation". To i...