function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sai tarunsai tarun 

One of the Interviewer askeed me to why we go with "custom duplicate management instead of inbuilt duplicate management"?

One of the Interviewer askeed me to why we go with "custom duplicate management instead of inbuilt duplicate management"?
that means we already have duplicate managemnet system, then why we go with trigger or apex like code for checking duplicate records......

please tell me the difference between them ......

Thanks in advance............
Best Answer chosen by sai tarun
NagendraNagendra (Salesforce Developers) 
Hi Sai,

Duplicate Management (Generally Available): Maintaining clean and accurate data is one of the most important things you can do to help your organization get the most out of Salesforce, so we’re excited to introduce Data.com Duplicate Management. Now you can control whether and when you allow users to create duplicate records inside Salesforce; customize the logic that’s used to identify duplicates, and create reports on the duplicates you do allow users to save.

Duplicate Management Limitations:
  • Duplicate management is available for accounts, contacts, leads, and custom objects. All other objects, including Opportunities and Person Accounts, are not currently supported.
  • Duplicate rules don’t run when records are created in following ways.
  • When records are created using Quick Create.
  • When leads are converted to accounts or contacts and your organization doesn’t have the “Use Apex Lead Convert” permission.
  • When a record is restored with the Undelete button.
  • When records are added using Exchange Sync.
  • When records are manually merged.
  • In some cases, if duplicate rules are set for an alert to show when potential duplicates are found, users will always be blocked from saving records and will not see a list of possible duplicates. Examples of this include the following.
  • When records are added using the data import tools.
  • When a person account is converted to a business account (and the newly created business account matches existing business accounts).
  • When records are added or edited using Salesforce APIs.
  • Standard and custom matching rules that use fuzzy matching methods only support Latin characters, and, if you’re using international data, we recommend you use the Exact matching method with your matching rules.
  • If a field on an object is no longer available to your organization, it may cause matching rules with mappings to this field to be ignored. This could affect your duplicate detection. Make sure you check all duplicate rule field mappings for an object if there is a change to the fields available to your organization. For example, the Clean Status field is only available to customers with a Data.com license. If your organization no longer has a Data.com license, this field is no longer available and matching rules with mappings to this field will be ignored.
  • The customizable alert text in duplicate rules isn’t supported by the Translation Workbench.
Custom Duplicate Management:  One of the biggest issues in Org's that I have seen is with duplicate records. But what is the best way to prevent this? With an easy trigger of course! 


Let take the Contact object, in my Org, everything is keyed off email, so we shouldn't have more than one contact with the same email address. And we need to not only protect against new Contacts, but we also need to ensure that if a User updates the email on the Contact that it too is not already in use before the update occurs. In order for the User to know that they are trying to Insert or Update incorrectly, we will have a field error show next to the email of the contact stating that one already exists.

Let's make(or update) a Contact trigger for before insert and before an update.
User-added imageWe are going to use a Map to store the id and email of each contact that comes into the trigger so we can use that to do a SOQL query later when its time to see if it already exists.  add the 'trigger.isBefore' even though we know this will only occur before so that this can be easily extended in the future and we won't have to go back and change the code.
User-added imageNow we need to populate the map with the Contact info so we can use it in the SOQL query next. We should also send up an error if the batch of Contacts that is being iterated over in the trigger contains more than one of the same email. 
User-added image
Now that we have the Map populated, or at least in theory it should be, we will query the DB to see if a Contact already exists with that email, and if so, show an error to the User, other wise do nothing and allow it to be inserted/updated. 
User-added imageAnd that's it. You can, of course, make this much more robust, so it not only compares email but also name and phone number too. 


This is where custom apex code comes in handy.

Hope this information helps.

Mark this as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra

All Answers

NagendraNagendra (Salesforce Developers) 
Hi Sai,

Duplicate Management (Generally Available): Maintaining clean and accurate data is one of the most important things you can do to help your organization get the most out of Salesforce, so we’re excited to introduce Data.com Duplicate Management. Now you can control whether and when you allow users to create duplicate records inside Salesforce; customize the logic that’s used to identify duplicates, and create reports on the duplicates you do allow users to save.

Duplicate Management Limitations:
  • Duplicate management is available for accounts, contacts, leads, and custom objects. All other objects, including Opportunities and Person Accounts, are not currently supported.
  • Duplicate rules don’t run when records are created in following ways.
  • When records are created using Quick Create.
  • When leads are converted to accounts or contacts and your organization doesn’t have the “Use Apex Lead Convert” permission.
  • When a record is restored with the Undelete button.
  • When records are added using Exchange Sync.
  • When records are manually merged.
  • In some cases, if duplicate rules are set for an alert to show when potential duplicates are found, users will always be blocked from saving records and will not see a list of possible duplicates. Examples of this include the following.
  • When records are added using the data import tools.
  • When a person account is converted to a business account (and the newly created business account matches existing business accounts).
  • When records are added or edited using Salesforce APIs.
  • Standard and custom matching rules that use fuzzy matching methods only support Latin characters, and, if you’re using international data, we recommend you use the Exact matching method with your matching rules.
  • If a field on an object is no longer available to your organization, it may cause matching rules with mappings to this field to be ignored. This could affect your duplicate detection. Make sure you check all duplicate rule field mappings for an object if there is a change to the fields available to your organization. For example, the Clean Status field is only available to customers with a Data.com license. If your organization no longer has a Data.com license, this field is no longer available and matching rules with mappings to this field will be ignored.
  • The customizable alert text in duplicate rules isn’t supported by the Translation Workbench.
Custom Duplicate Management:  One of the biggest issues in Org's that I have seen is with duplicate records. But what is the best way to prevent this? With an easy trigger of course! 


Let take the Contact object, in my Org, everything is keyed off email, so we shouldn't have more than one contact with the same email address. And we need to not only protect against new Contacts, but we also need to ensure that if a User updates the email on the Contact that it too is not already in use before the update occurs. In order for the User to know that they are trying to Insert or Update incorrectly, we will have a field error show next to the email of the contact stating that one already exists.

Let's make(or update) a Contact trigger for before insert and before an update.
User-added imageWe are going to use a Map to store the id and email of each contact that comes into the trigger so we can use that to do a SOQL query later when its time to see if it already exists.  add the 'trigger.isBefore' even though we know this will only occur before so that this can be easily extended in the future and we won't have to go back and change the code.
User-added imageNow we need to populate the map with the Contact info so we can use it in the SOQL query next. We should also send up an error if the batch of Contacts that is being iterated over in the trigger contains more than one of the same email. 
User-added image
Now that we have the Map populated, or at least in theory it should be, we will query the DB to see if a Contact already exists with that email, and if so, show an error to the User, other wise do nothing and allow it to be inserted/updated. 
User-added imageAnd that's it. You can, of course, make this much more robust, so it not only compares email but also name and phone number too. 


This is where custom apex code comes in handy.

Hope this information helps.

Mark this as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra
This was selected as the best answer
sai tarunsai tarun
Thank you very much.. :)
 
DoondiDoondi
Very well explained Mr.Nagendra, Thankyou So much!
sai tarunsai tarun
Hi nagendra,
can you please paste the the above code here for reference.....