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
pavan kumar 1156pavan kumar 1156 

Pls help me to write a trigger .!

Need tomerge the accounts and findout the duplicatea and eliminate them?
Naveen DhanarajNaveen Dhanaraj
Duplicate Management:
If you want to prevent from Entering Duplicate Records, you can use Standard Functionality Matching Rule and Duplicate Rule
 
These blogs will explain you step by step,
http://www.mstsolutions.com/blog/content/duplicate-management-salesforcecom
http://www.buanconsulting.com/duplicate-management-in-salesforce-com/
https://help.salesforce.com/articleView?id=managing_duplicates_overview.htm&type=0 (https://help.salesforce.com/articleView?id=managing_duplicates_overview.htm&type=0" target="_blank)
 

Matching Rule:https://help.salesforce.com/articleView?id=matching_rules_overview.htm&language=en_US&type=0
Duplicate Rule:https://help.salesforce.com/articleView?id=duplicate_rules_create.htm&language=en_US&release=206.5&type=0

If you have already Duplicate Records then by using This App filter it,
Try This Apps,
https://appexchange.salesforce.com/listingDetail?listingId=a0N300000058vzKEAQ
 https://appexchange.salesforce.com/listingDetail?listingId=a0N30000003IYLlEAO

Trigger to restrict after cleaning up the Duplicates,
trigger MatchEmailTrigger on CustomObj__c (before insert) {
       
    set<string> emailSet=new set<string>();
    for(CustomObj__c c:trigger.new)
    {
        emailSet.add(c.Email__c);
    }
   
    list<contact> clist=[select id from contact where email in:emailSet];
    list<lead> leadList=[select id from lead where email in:emailSet];
   
    if(clist.size()>0 || leadList.size()>0)
    {
    for(CustomObj__c c:trigger.new)
    {
        c.addError('Email Exists');
    }
}
}


 
Dinesh MultaniDinesh Multani
If you just want to merge duplicate Account then instead of writing trigger you can use Salesforce's inbuilt functionality for merging the Accounts. Just visit your Accounts at the bottom that page there is a "Tools" section in this section click on "Merge Accounts" and then you can just move ahead with Accounts you need to merge or you can visit this link where it is discussed in detail 
https://success.salesforce.com/answers?id=90630000000grryAAA