trigger duplicateAccount on Account (after insert,after update) {
set<string> duplicateSet = new set<string>();
Map<string,string> accMap = new Map<string,string>();
for(Account ac:trigger.new){
duplicateSet.add(ac.name);
}
for(Account a:[SELECT id,Name from Account where name IN:duplicateSet]){
accMap.put(a.name,a.Name);
system.debug('##############'+accMap );
}
for(Account account:trigger.new){
if(accMap.containsKey(account.name) ){
account.addError('Account is Already Exist');
}
}
}
set<string> duplicateSet = new set<string>();
Map<string,string> accMap = new Map<string,string>();
for(Account ac:trigger.new){
duplicateSet.add(ac.name);
}
for(Account a:[SELECT id,Name from Account where name IN:duplicateSet]){
accMap.put(a.name,a.Name);
system.debug('##############'+accMap );
}
for(Account account:trigger.new){
if(accMap.containsKey(account.name) ){
account.addError('Account is Already Exist');
}
}
}
No comments:
Post a Comment