Friday, 1 May 2015

Duplicate Rule (Duplicate Management) (Duplicate Record Creation when Duplicate Rule is Activated)


When we activate a duplicate rule on particular object then it prevent the duplicate record creation.
We can save the record even we have duplicate rule activated through apex.


I have to write a  test class.It contains the Contact record creation on which object we have duplicate rule activated.If i create a contact then it give you test failures then to avoid it we can use the "allowSave" property of " DMLOptions.DuplicateRuleHeader".


Database.DMLOptions dml = new Database.DMLOptions();
dml.DuplicateRuleHeader.AllowSave = true;
Contact duplicateContact = new Contact(LastName='Balaji');
Database.SaveResult sr = Database.insert(duplicateAccount, dml);
if (sr.isSuccess()) {
System.debug('Duplicate account has been inserted in Salesforce!');

Referred From:

No comments:

Post a Comment