I've currently enabled duplicate rules for the Contact object and specified the "Action on Create" and "Action on Edit" to "Block" incoming duplicate Contact records.
When testing with the example code provided in current documentation for the DmlOptions
Class I'm still getting duplicate errors when trying to insert a duplicate contact record:
Contact duplicate_contact = new Contact(firstName='Bob',
lastName='Duplicate',
email='[email protected]');
Database.DMLOptions dml = new Database.DMLOptions();
dml.DuplicateRuleHeader.allowSave = true;
dml.DuplicateRuleHeader.runAsCurrentUser = true;
Database.SaveResult sr = Database.insert(duplicate_contact, dml);
if (sr.isSuccess()) {
System.debug('Duplicate contact has been inserted in Salesforce!');
}
else system.debug('>>> Error Inserting Duplicate: '+ sr.getErrors());
Error Received:
You're creating a duplicate record. We recommend you use an existing record instead.
Anyone know why specifying duplicateRuleHeader.allowSave = true
would still produce this error?
allowSave
header. If it's set to block this will cause duplicate inserts to fail even whenallowSave = true