You need to sign in to do that
Don't have an account?
santhosh konathala 17
can anybody tell me the reason .Below is my Trigger code have compiled well but the Trigger functionality is working in update case only?
Trigger AccountAvoidDuplicate on Account(before insert,before update)
{
Map<id,account> map1=new map<id,account>();
list<account> acclist=[select id,name from account];
list<account> acclist1=new list<account>();
for(account acc:Trigger.new)
{
for(account a:acclist)
{
acclist1.add(a);
map1.putall(acclist1);
if(map1.containskey(acc.id))
{
acc.adderror('plz insert unique values');
}
}
}
}
{
Map<id,account> map1=new map<id,account>();
list<account> acclist=[select id,name from account];
list<account> acclist1=new list<account>();
for(account acc:Trigger.new)
{
for(account a:acclist)
{
acclist1.add(a);
map1.putall(acclist1);
if(map1.containskey(acc.id))
{
acc.adderror('plz insert unique values');
}
}
}
}
your trigger is on before insert so in this condition you don't have account id so how you can fill map with account id
cahnge you code to avoid duplicate value
try this trigger now if user create / update account with existing account name .user get a error message
Thanks
mark it best answer if it helps you :)
All Answers
your trigger is on before insert so in this condition you don't have account id so how you can fill map with account id
cahnge you code to avoid duplicate value
try this trigger now if user create / update account with existing account name .user get a error message
Thanks
mark it best answer if it helps you :)
I am learning So much from your side.A great thanks to you.