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