The duplicate detection feature was introduced long back in Dynamics CRM.
To enable it Navigate to Settings > Data Management and select Duplicate Detection Settings and select Enable duplicate detection option.
Next select Duplicate Detection Rules to either define the rule on which the duplicate detection rule should run or click on existing out-of-the-box rules.
Here open the “Contacts with same first name and last name” rule
Below you can see the rule criteria
To see it in action, you can try creating a new contact record with exact same first name and last name
Clicking on Save will allow you to create a duplicate contact record.
This is one of the limitations associated with the Duplicate Detection Rule along with other limitations like that. It works only for tables and not for phones, doesn’t work. When a lead is converted to account or contact using the qualify button and also there can be only 5 duplicate detection rules per entity.
Thankfully now you have an Alternate Key in Microsoft Dynamics CRM Development (introduced in CRM 2015 version), which you can use to prevent duplicate records to be created.
The basic purpose of the alternate key is to help define any other field apart from the GUID as the primary key for the entity. To match the external source in case of data migration.
Now let us define the alternate key on the First Name and Last Name field on the contact entity, similar to the above Duplicate Detection Rule.
Navigate to Customization > Customize the Entities > Entities and select the Contact entity and click on Keys.
Now try creating a new contact record with a duplicate first name and last name, you should get the below error message:
Defining alternate key makes sure that if records are getting created from code, then also check is applied i.e., server-side. Dynamics CRM services create a non-clustered unique index using the field defined in the database. One point we need to keep in mind is if any of the fields that are part of Alternate Key is blank or null. Then this check will not happen, and the record will not be identified as a duplicate.
In this article, we saw how easy it is to have duplicate detection in place without writing any code or specifically server-side code like plugins, custom workflow activity, etc.