Bypass Salesforce Duplicate Rule in Apex Class

Sample Code:

Database.DMLOptions dbDML = new Database.DMLOptions(); 
dbDML.DuplicateRuleHeader.allowSave = true;
dbDML.DuplicateRuleHeader.runAsCurrentUser = true;
Account duplicateAcc = new Account(Name='Salesforce');
Database.SaveResult sr = Database.insert(duplicateAcc, dbDML);
if (sr.isSuccess()) {
    System.debug('Duplicate account has been inserted in Salesforce!');

  • Riya

    Hi Biswajeet,

    I have one question related to find duplicate class is there is a way we can fetch the duplicates and non-duplicate contact list from this?

    Also, if not is there a way we can identify from my contact list which corresponding index contact is found as duplicate?


    • Hi Riya,

      Yes you can get duplicate records from “Duplicate Record Sets” & “Duplicate Record Set Items” objects.