You need to sign in to do that
Don't have an account?
Manjunath reddy 25
before trigger on opportunity to update the fields in account.
I'm currently trying to create a trigger that runs whenever an Opportunity is created or updated. The trigger needs to check all the other Opportunities related to the Account of the Opportunity being updated. It should check to see if any of the Opportunities have a StageName equal to 'Closed Won ', if so, it should update the account Type to 'Customer'. If none of the Opportunities are closed won, the Account Type should be 'Prospect'.but iam getting accs.get(o.accountId).type as null in debug log.can someone help me on this.
trigger updateAccountIfOppCustomer on Opportunity (before insert, before update) { list<opportunity> accOpps = new list<opportunity>(); list<id> accountIds = new list<id>(); for(opportunity opp:trigger.new){ accountIds.add(opp.accountId); } list<opportunity> opps = [select id,AccountId,StageName from opportunity where accountId IN:accountIds]; map<id,account> accs = new map<id,account>([select id,type from account where id IN:accountIds]); system.debug('accs '+accs ); for(opportunity o:opps){ if (o.StageName == 'Closed Won' || o.StageName == 'Customer Reseller') { //acc.type = 'prospect'; accs.get(o.accountId).type='prospect'; } } }
Try this:
(accs.get(o.accountId)).type='prospect';