You need to sign in to do that
Don't have an account?
Synthia Beauvais
System Query Exception: Aggregate Query
I am getting the following error for my contact count trigger below. I am not sure what this error means. It only affects 2 out of 300,000+ accounts in my org.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger NumberOfContacts caused an unexpected exception, contact your administrator: NumberOfContacts: execution of BeforeUpdate caused by: System.QueryException: Aggregate query has too many rows for direct assignment, use FOR loop: External entry point
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger NumberOfContacts caused an unexpected exception, contact your administrator: NumberOfContacts: execution of BeforeUpdate caused by: System.QueryException: Aggregate query has too many rows for direct assignment, use FOR loop: External entry point
// On Account trigger NumberOfContacts on Account (before insert, before update) { if(trigger.isinsert) for(account a:trigger.new) a.Number_of_contacts__c = 0; else for(account a:[select id,(select id from contacts) from account where id in :trigger.new]) trigger.newmap.get(a.id).Number_of_contacts__c = a.contacts.size(); for(account b:[select id,(select id from contacts where Inactive__c = False) from account where id in :trigger.new]) trigger.newmap.get(b.id).Number_of_active_contacts__c = b.contacts.size(); }
Below piece of code should help you.
I am getting Error: Compile Error: unexpected token: as at line 6 column 59 with your code.
Below should work
Scenarios: