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

Best Practices for Building Prompt Templates

 Hi, The following best practices should be considered when building prompt templates: Make sure that your prompt templates are concise and ...