Had a project where the client wanted to allow the data to bypass contact duplicate rules they had in place. So figured inserting the new contacts with Database.DMLOptions.DuplicateRuleHeader.allowSave
would do the trick.
It will indeed let you save over duplicate rules in place; however, if the record fails a validation rule it will fail silently
Example: There is a validation rule on Account, that throws an error when 'Fail_Me__c' = true.
Database.DMLOptions dmlOptions = new Database.DMLOptions();
dmlOptions.DuplicateRuleHeader.allowSave = true;
List<SObject> toInsert = new List<SObject>();
Account iPass = new Account();
iPass.Name = 'I Pass validation';
iPass.Fail_Me__c = false;
toInsert.add(iPass);
Account iFail = new Account();
iFail.Name = 'I Fail validation';
iFail.Fail_Me__c = true; // should get an error
toInsert.add(iFail);
Database.insert(toInsert, dmlOptions);
/*shouldn't get here but we do*/
System.debug('*** iPass.Id: ' + iPass.Id);
System.debug('*** iFail.Id: ' + iFail.Id);
Completes successfully, no errors, with a result of:
USER_DEBUG|[15]|ERROR|*** iPass.Id: 00136000002X7U5AAK
USER_DEBUG|[17]|ERROR|*** iFail.Id: null
Maybe I'm not using it correctly, but something seems off here right?
Database.SaveResult[] srList = Database.insert(toInsert, dmlOptions);
? and then check the isSuccess() method for each list member insrList
?