What options are available to prevent duplicate entries?

I am working to help minimize the appearance of duplicate accounts within our Salesforce environment. One alternative I found was to create a hidden field as a validation check – if that field is set to unique, and is attempted to be set as something which is a duplicate, it throws an error.

The problem, however, is that we have multiple systems interacting with Salesforce, one of which creates duplicate entries. I’m currently looking into writing a trigger where on an account creation/update, it checks for a duplicate entry, and if it finds one, merges the two together. Is it possible for triggers to fire off a merge? Or do I need to write in for all of the fields to port over?

Is there an alternative I am missing?


We have merge Call in triggers

merge triggers fire both before and after delete triggers for the losing records and before update triggers for the winning record only


List<Account> ls = new List<Account>{
new Account(Name='Acme Inc.'),
new Account(Name='Acme')};
insert ls;
Account masterAcct = [SELECT Id, Name
FROM Account WHERE Name = 'Acme Inc.'
Account mergeAcct = [SELECT Id, Name FROM
Account WHERE Name = 'Acme' LIMIT 1];
try { merge masterAcct mergeAcct;
 } catch (DmlException e) {
// Process exception here

Source : Link , Question Author : Plastinko , Answer Author : Mohith Shrivastava

Leave a Comment