Duplicate Management by Salesforce: Bypassing Certain Rules

October 9, 2015 Appirio

By Naresh Kumar Ojha


It’s quite interesting to work on Duplicate Management on Salesforce orgs. Preventing users from creating duplicate records is important and plays a great role in every organization’s data. Duplicate Management is a feature of Data.com that was released in Spring ‘15 due to high demand by customers. It enables Administrators to stop users from creating duplicate records, ignore duplicates, and create reports of ignored duplicates.

All this is great and necessary functionality. But on an earlier assignment, I ran into a problem with Duplicate Management. I had to create a web service and the requirement was: when we create any Account/Contact from the SFDC org, it should stop users from creating a new record because there is already one or more Account(s)/Contact(s) in the system by the same name. But as the external system’s users cannot interact with the SFDC org (system), business stakeholders wanted to give them the ability to create Account(s)/Contact(s) so that they could be merged (in case they contain valid, required information).

How to bypass duplicate rules on Account(s)/Contact(s)

As a solution, I had to implement a web service which could ignore duplicate rule(s) on Account(s)/Contact(s) and could create new records for these objects, and return the message to the end users. Here I’ve provided a brief overview of information which allows users to create records even if there are matching/duplicate rules created under the Duplicate Management implementation on the Salesforce orgs.

In REST API (below), this method is enforcing the insertion of duplicate records and fetching the already existing duplicate records. The method simply creates an Account and returns the list of duplicate accounts existing in the database:



global static Set<Id> requestAccount(String name, String phone, String website) {

 String responseMsg = ”;

 Set<Id> setDuplicateIds = new Set<Id>();

 Account account = new Account(Name = name, phone = phone, Website = website);

 Database.SaveResult sr = Database.insert(account, false);


 if (!sr.isSuccess()) {

   Datacloud.DuplicateResult duplicateResult;

//Insertion failed due to duplicate detected

for (Databse.Error duplicateError : sr.getErrors()) {

 duplicateResult = ((Database.DuplicateError)duplicateError).getDuplicateResult();



// Fetch the Ids of the existing duplicate records

for (Datacloud.MatchResult duplicateMatchResult : duplicateResult.getMatchResults()) {

 for (Datacloud.MatchRecord duplicateMatchRecord : duplicateMatchResult.getMatchRecords()) {




// If the duplicate rule is an alert rule, we can try to bypass it

Database.DMLOptions dml = new Database.DMLOptions();

dml.DuplicateRuleHeader.AllowSave = true;

Databsae.SaveResult sr2 = Database.insert(account, dml);

if (sr2.isSuccess()) {

 System.debug(‘Duplicate account has been inserted in Salesforce!’);



 return setDuplicateIds;


This solution should help you ignore duplicate rule(s) on Account(s)/Contact(s), so that you can create new records for these objects — even if there are matching/duplicate rules created under Duplicate Management.

Previous Article
Lightning Process Builder: How to Initiate the Approval Process
Lightning Process Builder: How to Initiate the Approval Process

By Rahul Agrawal Salesforce’s Spring 15 release launched a new feature called Lightning Process Builder. Pr...

Next Article
The 7 Best (Non-Lightning) Features in the Salesforce Winter ‘16 Release
The 7 Best (Non-Lightning) Features in the Salesforce Winter ‘16 Release

Anyone who livestreamed or even read about the Meet the New Salesforce event won’t be surprised that Salesf...