Is there a way to disable the duplicate check for an apex class?
I have an insert of contacts, where I have a custom duplicate check. Now I would like to disable the standard duplicate check for only that apex class.
Is there a way to disable the duplicate check for an apex class?
I have an insert of contacts, where I have a custom duplicate check. Now I would like to disable the standard duplicate check for only that apex class.
I think you can bypass duplicate check with DMLOptions.DuplicateRuleHeader Class: documentation
Sample:
Database.DMLOptions dml = new Database.DMLOptions();
dml.DuplicateRuleHeader.AllowSave = 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!');
}
Apparently the AllowSave only works if the duplicate rule is an Alert rule, not a Block rule.
When you try to save a record that’s identified as a duplicate record by a duplicate rule, you’ll receive a duplicate error. If the duplicate rule contains the Allow action, an attempt will be made to bypass the error.