trigger CountOfContactsRelatedToAccount onContact (after insert, after delete, after Undelete) {Set<Id> accId = new Set<Id>();if(Trigger.isInsert || Trigger.isUndelete){for(Contact con : Trigger.new){accId.add(con.AccountId);}}if(Trigger.isDelete){for(Contact con : Trigger.old){accId.add(con.AccountId);}}List<Account> accList = [Select Id,Name,Count_of_Contacts__c ,(Select id from contacts) from Account where Id IN : accId];for(Account acc :accList){acc.Count_of_Contacts__c = acc.contacts.size();}update accList;}
Thursday, April 6, 2023
Trigger for Count Number of Contacts Related To Account in Salesforce
Subscribe to:
Post Comments (Atom)
-
Beginner-Level Questions 1. What is MuleSoft, and what are its key features? Answer : MuleSoft is an integration platform that enables dev...
-
As a Salesforce Admin, Salesforce flows are one of the most effective ...
-
In this session/post we will learn about Integration Procedure Basics and learn about declarative server side processing in OmniStudi...
No comments:
Post a Comment