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!'); }