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
Raghav Sharma 39Raghav Sharma 39 

how can we do rollup summary to count the number of contacts on account by using workflow/process builder?

Deepali KulshresthaDeepali Kulshrestha
Hi Raghav,
Please go through the link below.
https://www.xgeek.net/salesforce/create-roll-up-summary-field-to-count-contacts-on-account-with-process-builder-and-flows/

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
Saransh BSaransh B
Process builder will be helpful in this case but not a workflow but I would suggest trigger because even though Salesforce mentioned that process builder is bulkified, It doesn't work same way everytime if more than 200 records are there.
CloudalyzeCloudalyze
Hi Raghav,

please check with the Trigger handler class,
 
public class CountContact {
    public static void countContactOnAccount(List<Contact> conList) {
       set<id> idset = new set<id>();
        for(Contact conObj : conList) {
            idset.add(conObj.AccountId);
        }
        List<Contact> countConList = [SELECT Id From Contact where Accountid =:idset];
        integer countCon = countConList.size();
        List<Account> accList = [SELECT Id,NumberOfEmployees From Account where id =:idset];
        List<Account> uppAccList = new List<Account>();
        for(Account accObj:accList) {
            accObj.NumberOfEmployees = countCon;
            uppAccList.add(accObj);
        }
        update uppAccList;
    }
}
-------------------------------------------
Contact trigger,

 
trigger ContactTrigger on Contact (After insert) {
CountContact.countContactOnAccount(Trigger.new);
}


Try this and let us know..........