You need to sign in to do that
Don't have an account?
Rajendra Prasad 44
i need to show error message when duplicate account record is created based on account Name
trigger acctrigger on Account (before insert) {
if(trigger.isBefore){
if(trigger.isInsert){
list<Account> acc = [SELECT Id,Name from Account];
for(Account ta: trigger.new){
for(Account a: acc){
if(ta.Name == a.Name){
newval.addError('sorry you cannot add this account its already been in database');
}
}
}
}
}
}
if(trigger.isBefore){
if(trigger.isInsert){
list<Account> acc = [SELECT Id,Name from Account];
for(Account ta: trigger.new){
for(Account a: acc){
if(ta.Name == a.Name){
newval.addError('sorry you cannot add this account its already been in database');
}
}
}
}
}
}
t
All Answers
Avoid using nested for loops. I tried this and it works fine:
t