public class countthecontacts {
public void insertcontact(){
list<Account> acclist = new list<Account>();
list<contact> conlist = new list<contact>();
set<id> accids = new set<id>();
for(contact con : conlist){
accIds.add(con.accountId);
}
for(account acc:[select id,No_of_Contacts__c,(select id from contacts) from account where id in:accids]){
acc.No_of_Contacts__c=conlist.size();
acclist.add(acc);
}
update acclist;
}
}
-
1Hi Keerthi. What did you try so far? Did you read any of the documentation on creating test classes yet?– Guy ClairboisCommented Jun 28, 2019 at 7:51
-
1Is there a reason you are not using a formula field on Account to do this for you instead of using code? This code is troublesome since it doesn't consider bulkified insert of multiple contacts either.– Phil WCommented Jun 28, 2019 at 8:52
Add a comment
|