This post explains how to prevent creating duplicate accounts in Salesforce.
Trigger :
trigger Prevent_duplicacy on Account (before insert) {
Set<string> str=new Set<string>();
for(Account acc:trigger.new)
{
str.add(acc.name);
}
List<Account> acc= new List<Account>([select name from Account where name in:str]);
for(Account a:trigger.new)
{
if(acc.size()>0)
{
a.adderror('error');
}
}
}
As I already have an account named Microsoft in my org.. When I am trying to create a new account with same the name it shows an error.
Thanks,
Lovesalesforceyes
nice
ReplyDelete