You need to sign in to do that
Don't have an account?
viswsanath
How to count the number of records on opportunity associated with on Account ?
HI ,
How to count the number of records on opportunity associated with on Account ? pls give me exammple ,
kindly help me on this
viswsanath
How to count the number of records on opportunity associated with on Account ? pls give me exammple ,
kindly help me on this
viswsanath
You need to create roll-up summary field to achieve the requirements.
Go through the below documents to understand how to create roll-up summary field
- https://help.salesforce.com/articleView?id=fields_about_roll_up_summary_fields.htm&type=0
- https://trailhead.salesforce.com/en/point_click_business_logic/roll_up_summary_fields
Please accept my solution as Best Answer if my reply is helpful.trigger Rolluptriggroncontact on Contact (after insert,after update,after delete,after undelete) {
set<id> setlst = new set<id>();
if(trigger.isinsert||trigger.isupdate||trigger.isundelete){
for(contact c :trigger.new){
if(c.AccountId != null)
setlst.add(c.AccountId);
}
}
if(trigger.isupdate||trigger.isdelete){
for(contact oldcon :trigger.old){
if(oldcon.AccountId != null)
setlst.add(oldcon.AccountId);
}
}
if(setlst.size()>0){
List<account> acclst =[select id,No_of_Contacts_in_SFDC__c,(select id from contacts) from account where id in :setlst];
list<account> updaterec = new list<account>();
for(account acc : acclst){
acc.No_of_Contacts_in_SFDC__c =acc.contacts.size();
updaterec.add(acc);
}
update updaterec;
}
}
simple change instead of contact to opportunity