Hi Naveen,Below is the code for you, just copy paste:
Mark solved if it works as expected for your requirmenttrigger addTeam on Opportunity (After insert) {
Set<Id> setOfAccountIds = new Set<Id>();
List<Account> lstAccountToUpdate = new List<Account>();
for(Opportunity opp : trigger.new) {
if(opp.StageName != 'Closed Won' && opp.StageName != 'Closed Lost' && opp.AccountId != null) {
setOfAccountIds.add(opp.AccountId);
}
}
for(Account acc : [Select Id, Open_opportunities_count__c, (Select Id, StageName From Opportunities Where
StageName != 'Closed Won' AND StageName != 'Closed Lost'),
Name From Account Where Id IN:setOfAccountIds]) {
lstAccountToUpdate.add(new Account(Id = acc.Id, Open_opportunities_count__c = acc.Opportunities.size()));
}
if(!lstAccountToUpdate.isEmpty())
update lstAccountToUpdate;
}
3 件の回答