function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
trigger countopprec on Opportunity (After insert,After Delete,After Undelete) {
set<id>accountIds=new set<id>();
if(trigger.isInsert || trigger.isUndelete){
for(opportunity o:trigger.new){
accountIds.add(o.AccountId);
}
}
if(trigger.isDelete){
for(opportunity o:trigger.old){
accountIds.add(o.Accountid);
}
}
List<Account>acclist=[select id,name,No_of_opportunities__c,(select id,stageName,closeDate,name from opportunities)from Account where id=:accountids];
for(Account a :acclist){
a.No_of_opportunities__c=a.opportunities.size();
}
update acclist;
}
mark as best answer if it helps,
Thanks
You can tweak the solution provided in https://salesforce.stackexchange.com/a/206670/80089 as per your requirement
If this information helps, please mark the answer as best. Thank you