Write A trigger like (Trigger Trigger_Name On Account(After insert, After update) For count the Number of contacts related to particular account, and display count value in account Object..., Anyone give proper answer for this
Getting following error while trying to save class: Line 27: Illegal assignment from List to Decimal
Error while trying to save trigger: Line 4: Method does not exist or incorrect signature: void contactsCount(List<Account>, NULL, String) from the type updateAccountWithcontactsCount Line 6: Method does not exist or incorrect signature: void contactsCount(List<Account>, Map<Id,Account>, String) from the type updateAccountWithcontactsCount Line 8: Method does not exist or incorrect signature: void contactsCount(List<Account>, Map<Id,Account>, String) from the type updateAccountWithcontactsCount
Tried the code but getting these error messages: unexpected syntax:'mismatched input '('expecting LCURLY' with apex class on Line 1 Method does not exist or incorrect signature: void AfterInsertLogic(List<Account>) from the type countContactsonAccount on trigger Method does not exist or incorrect signature: void AfterUpdateLogic(List<Account>, Map<Id,Account>) from the type countContactsonAccount on trigger
Trigger should be written on Contact as Account is Lookup on it.Also Account should be updated when contact got deleted.
Line 27: Illegal assignment from List to Decimal
Error while trying to save trigger:
Line 4: Method does not exist or incorrect signature: void contactsCount(List<Account>, NULL, String) from the type updateAccountWithcontactsCount
Line 6: Method does not exist or incorrect signature: void contactsCount(List<Account>, Map<Id,Account>, String) from the type updateAccountWithcontactsCount
Line 8: Method does not exist or incorrect signature: void contactsCount(List<Account>, Map<Id,Account>, String) from the type updateAccountWithcontactsCount
How to rectify these errors?
Regards
Chetan
{
if(trigger.isInsert && Trigger.IsAfter)
AfterInsertLogic(Trigger.new);
}
if(trigger.isUpdate && Trigger.IsAfter)
AfterUpdateLogic(Trigger.new,Trigger.OldMap);
}
}
Public static class calcuateCOntactCOunt()
{
Public static AfterInsertLogic(List<Account> listAcc)
{
set<Id> accountIDS = new Set<Id>();
List<Account> count = new List<Account>();
for(Account acc :listAcc){
accountIDS.add(acc.id);
}
Integer contactCounts = [Select count(Id) from contacts where accountid in :accountIDS];
for (Account a : accountIDS)
{
Account a = new Account(id=a.Id,countfield=contactCOunts);
count.add(a);
}
if(count.size()>0)
{
update count;
}
}
Public static AfterUpdateLogic()
{
// write something like insert
}
}
unexpected syntax:'mismatched input '('expecting LCURLY' with apex class on Line 1
Method does not exist or incorrect signature: void AfterInsertLogic(List<Account>) from the type countContactsonAccount on trigger
Method does not exist or incorrect signature: void AfterUpdateLogic(List<Account>, Map<Id,Account>) from the type countContactsonAccount on trigger
Hi Harish,
Please try this piece of code. Hope it will help you.
Trigger :
Hanler :If this code helps you. Please m ark it as best.
Regards,
Suraj