• Suman Koley
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
I have written a trigger to count the number of contacts in accounts. Please help me with writing the handler class of it. I have very less knowledge on handler class:
trigger tocountcontactrecords on Contact (after insert) {

set<ID> setID = new set<ID>();
List<Account> ListAccount = new List<Account>();

for(contact con : trigger.new)

{
setID.add(con.AccountID);
}
For(account acc:[select id,name,Numberofcount__c,(select id from contacts) from account where id=:setID])

{

Account Ac1 = new Account();
ac1.Id=acc.Id;
ac1.Numberofcount__c = acc.contacts.size();
Listaccount.add(ac1);

}

update Listaccount;


}
I have written a trigger to count the number of contacts in accounts. Please help me with writing the handler class of it. I have very less knowledge on handler class:
trigger tocountcontactrecords on Contact (after insert) {

set<ID> setID = new set<ID>();
List<Account> ListAccount = new List<Account>();

for(contact con : trigger.new)

{
setID.add(con.AccountID);
}
For(account acc:[select id,name,Numberofcount__c,(select id from contacts) from account where id=:setID])

{

Account Ac1 = new Account();
ac1.Id=acc.Id;
ac1.Numberofcount__c = acc.contacts.size();
Listaccount.add(ac1);

}

update Listaccount;


}