Duplicate records cause inaccuracies, frustration, and challenges for all Salesforce admins, so it is very important to prevent duplicates in Salesforce.
In this Salesforce tutorial, I will guide you through the different ways to prevent duplicate records in Salesforce. I will explain the salesforce duplicate rules and matching rules.
Also, I will let you know the other ways to prevent duplicate records in Salesforce, such as the validation rule.
Prevent Duplicate Records in Salesforce
You have all heard the famous quote, “Prevention is better than cure”. It means all Salesforce admins need to prevent duplicate records and maintain a clean database before its too late.
There are multiple ways in Salesforce using which you can avoid creating duplicate records in Salesforce, such as:
- Salesforce Duplicate Rules and Matching Rules
- Validation Rule for duplicate records in Salesforce
- Third-party paid and free tools of Salesforce
Moreover, even if your organization guarantees you that they don’t have duplicate records in their Salesforce org, don’t trust them. It is never ever possible; maybe you will only get one record, but duplicate data is there. You can prove them by finding duplicate records in Salesforce.
Let’s learn each of the ways to remove duplicates in Salesforce.
Salesforce Duplicate Rules and Matching Rules
Duplicate Rules and Matching Rules in Salesforce are one way to find duplicate data in your org and prevent you from creating it.
The Duplicate rules and Matching Rules work together for duplicate management and make your org free of duplicates. So, let’s first understand what they both are.
Salesforce Duplicate Rules
From its name, you can get its meaning. Duplicate Rules in Salesforce are a set of rules that are used to prevent the creation of duplicate records in your org.
Duplicate rules view or search the records with duplicates and stop or alert you to create a new one before you are going to save them.
By default, Salesforce has some of the standard duplicate rules for accounts, contacts, and leads. Based on the organization’s need, Salesforce allows the admin to create custom duplicate rules, too.
Salesforce Matching Rules
In Salesforce, matching rules are criteria that identify duplicate records. It defines on which basis duplicate records are identified in the duplicate rule.
As Salesforce provides standard duplicate rules for accounts, contacts, and leads, it means it also provides the matching rules for all of them because they both work together, and it is not possible to define the action without defining when to take it.
Additionally, the admin can create custom matching rules too as per the requirement.
Salesforce Duplicate Rule Example
Suppose an organization uses Salesforce and wants to make sure that a customer record with the same first name, last name, email, and mobile number is not allowed to be created again and is considered a duplicate record.
For this, the admin first needs to define that matching rule, then define the action, i.e., duplicate rule, that stops the user from creating a duplicate record.
Let’s learn how to prevent duplicates in Salesforce using matching rules and duplicate rules.
Create Matching Rule in Salesforce
Below are the steps to create a custom matching rule in Salesforce. Consider the above-defined example to understand it.
1. Go to the “Setup”, search “Matching Rules” in “Quick Find”, and click on it.

2. Click on the “New Rule” button to create a new matching rule.

3. Choose the “Object” from the dropdown on which you want to apply this rule.

4. Enter the detail:
| Fields | Description |
|---|---|
| Rule Name | Specify the name of the matching rule. |
| Unique Name | It automatically populated based on the rule name and acts as an API name. |
| Description | Optionally, you can add the extra information about the matching rule. |

5. Define the matching rule criteria that define which fields to compare and how.
| Fields | Description |
|---|---|
| Field | Specify the field that you want to define in the matching rule. |
| Matching Method | Define the matching method. You have two options: either you can exactly match the value of the field, or you can fuzzy (similar kind of value with slight difference) match the value of the field. |
| Matching Blank Field | If you check this checkbox, it treats the records as duplicated if the field left to be blank. |
| Filter Logic | By default, filter logic is set to AND on which fields are compared. You can change it as per your requirement also. |
6. Click on the “Save” button.

7. If you want to use this matching rule, make sure to click on the “Activate” button. You will receive an email regarding the activation also.

Create Duplicate Rules in Salesforce
Once you define the criteria for knowing the record to duplicate, the next step is to set up the action that you want to take for this.
Note: You can also directly create the “Duplicate Rule” without creating the “Matching Rule” in Salesforce.
Below are the steps to create duplicate rules in Salesforce. Consider the above-defined example to understand it.
1. Navigate to the “Setup”, in “Quick Find”, search for “Duplicate Rules”, and click on it.

2. Click on the “New Rule” dropdown and specify the object from the list for which you want to create a duplicate rule.

3. Enter the Rule Details:
| Fields | Description |
|---|---|
| Rule Name | Specify the name for the duplicate rule. |
| Description | Optionally, you can give more detail about the rule that you created. |
| Record Level Security | Specify the record level security that defines which records are to be considered while duplicate rule matching. You have two options as follow: Enforce Sharing Rules: This rule checks duplicates only for those records that belong to the user that has access to this record. Bypass Sharing Rules: The rule checks duplicates for all the records without taking into consideration record access. |

4. Specify the action that will happen when users try to save the duplicate record.
| Fields | Description |
|---|---|
| Action On Create | Define the action that you want to take while checking duplicate at creation time. You will get two options: Allow: It allows you to create a duplicate record before giving you an alert and report as per the chosen option. Block: It does not allow the user to create a record with duplicate data. |
| Action on Edit | Similar to action on create, you can define action while editing the records that act as duplicates. |
| Alert Text | You can define the alert text that you want to display when you encounter a duplicate record. |

5. Define the matching rules on which bases duplicate records are identified.
| Fields | Description |
|---|---|
| Compare With | Define the object with whom you want to compare the duplicate record of this object. |
| Matching Rule | Specify the matching criteria on which the record is to be compared. If you don’t create the matching rule, you can create it by clicking on “Create New Matching Rule”. |
| Add Rule & Remove Rule | You can add more than one rule to check duplicate records by clicking on the “Add Rule” button, and to remove the rules, click on the “Remove Rule” button. |

6. Define the conditions the record must meet to run the rule. For example, if you have more than one type of customer, you can define the rule will run only for specific types of customers.

Below is the standard matching lead rule on which the duplicate lead rule works and stops the user from creating or editing duplicate records in the lead.
7. Click on the “Save” button. Then, click on the “Activate” button.

Let’s test how the duplicate rules work when you trying to create the record with the same first name, last name, mobile, and email.

Prevent Duplicate Leads in Salesforce
By default, Salesforce provides you with the standard duplicate rules and matching rules for the leads. The standard rule finds duplicate contacts and leads based on a defined matching rule, and this rule is activated by default.
If you want, you can add the custom matching rules to the standard lead duplicate rule, but you can not edit the standard lead matching rule.
(First Name AND Last Name AND Title AND Company)
OR (First Name AND Last Name AND Email)
OR (First Name AND Last Name AND Phone AND Company)
OR (First Name AND Last Name AND Mailing Street AND (City OR ZIP OR Phone))
OR (First Name AND Last Name AND Mailing Street AND Title)
OR (First Name AND Last Name AND Title AND Email)
OR (First Name AND Last Name AND Phone)Let’s learn how to prevent duplicate leads in Salesforce based on the standard duplicate rule.
Example-1: Default Action
By default, the standard lead duplicate rule allows the users to create and edit the duplicated record with an alert message and report.

If you are trying to save the new lead with the same “First Name”, “Last Name”, and “Phone”, the default lead rule warns the user with the message that your record looks like a duplicate record.

If you want, you can check the duplicate record to whom it looks the same by clicking on “View Duplicates”.

Example-2: Block Lead from creating and editing
If you want, you can stop the user from creating or editing the lead record with the duplicate rule.
It does allow users to save the record. To block the lead for creating and editing duplicate records, change the “Action On Create” and “Action On Edit” to “Block”.


Example-3: Default Sharing Rule
By default, the standard lead duplicate rule specifies the sharing rule to “Enforce sharing rules” that allow the different owners to create a record with already existing record information.

But if you want to stop the duplicate record from creating and editing, if the record still exists with a different owner, you need to change the record level security from “Enforce Sharing Rules” to “Bypass Sharing Rules”.


How to Prevent Duplicate Records in Salesforce using Validation Rule
You can also prevent duplicate records from being entered in Salesforce using the Validation Rule. In the Validation Rule, you will have one function named “PRIORVALUE”; you can use it to stop the duplicate record.
Moreover, you don’t need to specify whether you are creating the record or editing the record duplicate. If the formula created using the function found the same value already, it raises an error.
Also, it does not give the alert and allows the user to save the record with duplicate value afterward. The validation rule raises the duplicate record error and doesn’t allow the record to be saved. Also, the record access does not matter to validation works.
Below are the steps to create a validation rule in Salesforce that prevents duplicate records:
1. Go to the “Setup” and click on the “Object Manager” in the “Navigation Bar”.
2. Search the “Object” on whose records you want to prevent duplicate records from being entered and click on it.
For example, let’s prevent duplicate “Accounts” from being created based on the “Account Name” field.

3. Click on the “Validation Rules” from the left sidebar. Then, click on the “New” button to create a validation rule.

4. Enter the details:
| Fields | Description |
|---|---|
| Rule Name | Enter the name for the validation rule. |
| Active | Check the active checkbox to make the validation rule in use. |
| Description | Add the additional information about the validation rule. |

5. Enter the formula using the PRIORVALUE function to prevent the duplicate record from being created or edited.
PRIORVALUE(Name) = Name
6. Define the error message that you want to appear when the above-defined formula becomes true, i.e., when you try to save a record with a duplicate account name.
Duplicate Record Found: A Record with the same Account Name already exists. Also, specify the location where you want to display the error message.
7. Click on the “Save” button.

Let’s test how the validation rules work when you are trying to create the record with the same account name.

Conclusion
I hope you have understood how to avoid creating duplicate records in Salesforce. I have explained the duplicate and matching rules method to prevent duplicate records in Salesforce.
I also explain how you can prevent duplicate records in Salesforce using validation rules and scenarios to prevent duplicate leads using the standard duplicate lead rule in Salesforce.
You may like to read:
- How to Create Workflow Rule in Salesforce
- How to Duplicate a Report in Salesforce
- Create a Junction Object in Salesforce
I am Bijay Kumar, the founder of SalesforceFAQs.com. Having over 10 years of experience working in salesforce technologies for clients across the world (Canada, Australia, United States, United Kingdom, New Zealand, etc.). I am a certified salesforce administrator and expert with experience in developing salesforce applications and projects. My goal is to make it easy for people to learn and use salesforce technologies by providing simple and easy-to-understand solutions. Check out the complete profile on About us.