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.
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.
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
please check with the Trigger handler class,
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,
CountContact.countContactOnAccount(Trigger.new);
}
Try this and let us know..........