8

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.

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

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!'); 
}
  • 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. – Frederik Witte 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? – Yury Bondarau Sep 1 '16 at 14:57
2

Apparently the AllowSave only works if the duplicate rule is an Alert rule, not a Block rule.

Documentation

  • @ 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. – Jesper Bjerrum 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.