+ Start a Discussion
Lakshmi SLakshmi S 

standard field

HI All

How to prevent duplicates in to the standard name field?
Best Answer chosen by Lakshmi S
buggs sfdcbuggs sfdc
Hi 
May this link helps you out
http://developer.force.com/cookbook/recipe/preventing-duplicate-records-from-saving

Thanks
Mark it as correct answer if it helps you!

All Answers

buggs sfdcbuggs sfdc
Hi 
May this link helps you out
http://developer.force.com/cookbook/recipe/preventing-duplicate-records-from-saving

Thanks
Mark it as correct answer if it helps you!
This was selected as the best answer
SandhyaSandhya (Salesforce Developers) 
Hi 
Lakshmi Narasimha,


You can write trigger using before insert event.

Please see below trigger which throws an error when account already exists.
 
trigger duplicatePreventer on Account (before insert) {
   List<Account> acct= [select id, name from Account];
    for(Account a:acct)
    {
        for(Account a1:Trigger.New)
        {
            if(a.Name==a1.Name)
            {
               //a1.name.adderror('Account already exist'); 
                a1.adderror('Account already exist');
            }
                
        }
    }

}

Hope this helps you!

Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
 
Thanks and Regards
Sandhya