You need to sign in to do that
Don't have an account?
nitin sharma
Trigger on contact object and showing results on the account object
Hi,
I have checkbox field on the contact object and i have to show the count of the contacts on which this checkbox field have been checked on the account object..I am getting the followign error.I am not sure where I am going Wrong.Can somebody please help?
The error is:-Method does not exist or incorrect signature: [String].Size() at line 32 column 39
trigger BillingContactsCount on Contact (after Insert,after update) {
list<id> accountids=new list<id>();
for(contact c:trigger.new)
{
if(c.billingcontacts__c==true)
{
Accountids.add(c.accountid);
System.debug('The account type checks are as follows'+Accountids.get(0));
}
}
list<contact> cc=[Select id,billingcontacts__c,Accountid from contact where accountid in:Accountids and billingcontacts__c=true];
Map<ID,String>m=new map<ID,String>();
for(Contact d:cc)
{
m.put(d.accountid,d.id);
}
for(Id ids:Accountids)
{
Account acc=new account(id=ids);
acc.ContactCount__c=m.get(acc.id).Size();
}
}
I have checkbox field on the contact object and i have to show the count of the contacts on which this checkbox field have been checked on the account object..I am getting the followign error.I am not sure where I am going Wrong.Can somebody please help?
The error is:-Method does not exist or incorrect signature: [String].Size() at line 32 column 39
trigger BillingContactsCount on Contact (after Insert,after update) {
list<id> accountids=new list<id>();
for(contact c:trigger.new)
{
if(c.billingcontacts__c==true)
{
Accountids.add(c.accountid);
System.debug('The account type checks are as follows'+Accountids.get(0));
}
}
list<contact> cc=[Select id,billingcontacts__c,Accountid from contact where accountid in:Accountids and billingcontacts__c=true];
Map<ID,String>m=new map<ID,String>();
for(Contact d:cc)
{
m.put(d.accountid,d.id);
}
for(Id ids:Accountids)
{
Account acc=new account(id=ids);
acc.ContactCount__c=m.get(acc.id).Size();
}
}
Try below code.
All Answers
Try below code.
You have been of graeat help