You need to sign in to do that
Don't have an account?
sfdev1
I have created a custom field called 'Status' on the Account object. I has three picklist values : Prospect, Active and Dormant
The default is Propects' I an Opportunity is Closed -Won then I want to update the Account.Status field to Active
I started with the following code
trigger Test on Opportunity (after insert, after update) {
List<Account> accToUpdate= new List<Account>;
Trigger on Opportunity that update the Account Object not working
I have created a custom field called 'Status' on the Account object. I has three picklist values : Prospect, Active and Dormant
The default is Propects' I an Opportunity is Closed -Won then I want to update the Account.Status field to Active
I started with the following code
trigger Test on Opportunity (after insert, after update) {
List<Account> accToUpdate= new List<Account>;
for (Opportunity opp : System.Trigger.new) {
Account accounts = [select id,name,industry from account where id in opp.accountid];
for (Account acc: accounts){
if (acc.status__c != 'Active'){
acc.staus__C = 'Active';
accToUpdate.add(acc);
}
}
Account accounts = [select id,name,industry from account where id in opp.accountid];
for (Account acc: accounts){
if (acc.status__c != 'Active'){
acc.staus__C = 'Active';
accToUpdate.add(acc);
}
}
}
update accToUpdate;
update accToUpdate;
}
I'll also recommend to use Maps for bulk updates.