I have a trigger that updates/ inserts opportunities when the account is created. This was implemented by a third party. Now I would like to update the opportunities to Cancelled when the Account status= 'Cancelled'.
I have tried this via workflow rules and field update but this did not work. Below is my attempt to create the trigger, but I think its terribly wrong. Help would be greatly appreciated.
trigger updateopporutnites on Account (after update) {
Set<String> Account=new Set<String>();
for(Account ac : Trigger.new)
{
if(ac.Status__c=='Cancelled')
Account.add(ac.OpportunityId);
}
for(Opportunity opp : [select id, StageName from Opportunity where id in: Account])
{
opp.StageName='Closed - Cancelled';
update opp;
}
}