You need to sign in to do that
Don't have an account?
Ankita dixit
Method does not exist or incorrect signature: void add(Account) from the type Set<Id>
What is this type of error means: what is possible solution?
trigger ApexTrigger10 on Contact (After insert,After Delete) {
set<id> contactSet = new set<id>();
List<Account> newAccountList = new List<Account>();
if(trigger.isInsert && trigger.isAfter){
for(Contact con:trigger.new){
contactSet.add(con.Account);
}
}
if(trigger.isDelete && trigger.isAfter){
for(Contact con:trigger.old){
contactSet.add(con.Account);
}
}
List<Account> Acc= [SELECT id, name,(SELECT id,name from contacts) FROM Account WHERE id IN:contactSet];
for( Account a : Acc)
{
a.Total_number_of_contacts__c= a.contacts.size();
newAccountList.add(a);
}
update newAccountList;
}
trigger ApexTrigger10 on Contact (After insert,After Delete) {
set<id> contactSet = new set<id>();
List<Account> newAccountList = new List<Account>();
if(trigger.isInsert && trigger.isAfter){
for(Contact con:trigger.new){
contactSet.add(con.Account);
}
}
if(trigger.isDelete && trigger.isAfter){
for(Contact con:trigger.old){
contactSet.add(con.Account);
}
}
List<Account> Acc= [SELECT id, name,(SELECT id,name from contacts) FROM Account WHERE id IN:contactSet];
for( Account a : Acc)
{
a.Total_number_of_contacts__c= a.contacts.size();
newAccountList.add(a);
}
update newAccountList;
}
You have reffered the Account Lookup Api name wrongly in below line so you are getting this error...
contactSet.add(con.Account); ==> contactSet.add(con.AccountId);
Please try the below code:
Thanks,
Maharajan.C
All Answers
You have reffered the Account Lookup Api name wrongly in below line so you are getting this error...
contactSet.add(con.Account); ==> contactSet.add(con.AccountId);
Please try the below code:
Thanks,
Maharajan.C