Friday, 1 May 2015

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

Hi,

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.

Scenario:

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".

Eg:

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:
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_class_Database_DMLOptions_DuplicateRuleHeader.htm



No comments:

Post a Comment

Best Practices for Building Prompt Templates

 Hi, The following best practices should be considered when building prompt templates: Make sure that your prompt templates are concise and ...