function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

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 

Amit Chaudhary 8Amit Chaudhary 8
You can create the rollup summery field on Account to count the record
Sudipta DebSudipta Deb
Hi 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  Please accept my solution as Best Answer if my reply is helpful.
Mahesh K 22Mahesh K 22
Hi  viswsanath

trigger Rolluptriggroncontact on Contact (after insert,after update,after delete,after undelete) {
   set<id> setlst = new set<id>();
    for(contact c{
        if(c.AccountId != null)
        for(contact oldcon :trigger.old){
            if(oldcon.AccountId != null)
        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();
        update updaterec; 

simple change instead of contact to opportunity