11

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.

2
  • What is this 'standard' duplicate check?
    – bananka
    Jun 4 '15 at 13:02
  • The data.com duplicate management Jun 4 '15 at 13:02
22

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!'); 
}
3
  • Amazing! It works. Would you mind to share the code from the site in your answer? If one day the link will be down, your answer wont be helpful for others. Thank you really much. Jun 4 '15 at 14:42
  • Glad that it helped. I've updated the answer with the sample code.
    – bananka
    Jun 4 '15 at 15:43
  • Tried the similar code in trigger and it does not work. Does anybody know about any limitations in trigger context? Sep 1 '16 at 14:57
6

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.

Documentation

2
  • @ Ratan the above isn't what I'd consider a link only answer. He's provided a link to the reference documentation where the user can find further information about his answer.
    – crmprogdev
    Jan 28 '16 at 17:04
  • Didn't have enough cred to add a comment. Feb 3 '16 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.