You need to sign in to do that
Don't have an account?
masthan khan
Trigger+ when ever opportunity stagename =closedwon automatically update the account field rating=hot
Hai,
I am trying following sceanrio
Trgger when ever opportunity stagename =closedwon automatically update the account field rating=hot.
the account field rating is not updating automatically.
trigger stage_closedwon_account_hot on Opportunity (after insert, after update) {
set<id> ids=new set<id>();
list<account> accs=new List<account>();
for(opportunity a:trigger.new){
if(a.stagename=='closed won'){
id keys=a.account.id;
ids.add(keys);
}
}
accs=[select id,rating from account where id=:ids];
for(account ac:accs){
ac.rating='hot';
}update accs;
}
Regards
Masthan
I am trying following sceanrio
Trgger when ever opportunity stagename =closedwon automatically update the account field rating=hot.
the account field rating is not updating automatically.
trigger stage_closedwon_account_hot on Opportunity (after insert, after update) {
set<id> ids=new set<id>();
list<account> accs=new List<account>();
for(opportunity a:trigger.new){
if(a.stagename=='closed won'){
id keys=a.account.id;
ids.add(keys);
}
}
accs=[select id,rating from account where id=:ids];
for(account ac:accs){
ac.rating='hot';
}update accs;
}
Regards
Masthan
Mr.Steven Nsubuga it not working the account rating is not getting updated.
with regards
Masthan.
The issue is with line below in your code
Here account Id will always get null because we can not get account.Id from trigger.new.
try below code
Try this below code :
trigger stage_closedwon_account_hot on Opportunity (after insert, after update) {
set<id> ids=new set<id>();
list<account> accs=new List<account>();
for(opportunity a:trigger.new){
if(a.stagename=='Closed Won'){
id keys=a.accountid;
ids.add(keys);
}
}
accs=[select id, rating from account where id IN :ids];
for(account ac:accs){
integer i=0;
ac.Id=accs[i].id;
ac.rating='Hot';
i++;
}
update accs;
}
Thanks,
K.Kamala,Jenefa
Sweet Potato Tec.