You need to sign in to do that
Don't have an account?
pdo
"Aggregate query has too many rows for direct assignment" Error
I read in some other posts that this may be a bug, but I did not see resolution. Here is my code for my trigger and it works just fine in the Sandbox, but it does not work in production. Can anyone help with this?
trigger PhysicianUpdateAccountContactCount on Contact (after delete, after insert, after undelete, after update) { // Declare the variables public set<Id> AccountIDs = new Set<Id>(); public list<Account> AccountToUpdate = new List<Account>(); // Build the list of Accounts to update if(Trigger.isInsert || Trigger.isUnDelete || Trigger.isUpdate){ for(Contact c: Trigger.new){ if(c.role__c == 'Physician') AccountIDs.add(c.accountid); } } if(Trigger.isDelete || Trigger.isUpdate){ for(Contact c: Trigger.old){ if(c.role__c == 'Physician') AccountIDs.add(c.accountid); } } // Update the Accounts if(AccountIDs.size()>0){ for(Account a: [Select a.Id, a.Calc_Physicians__c, (Select Id From Contacts where Role__c = 'Physician') From Account a where Id in :AccountIDs]) AccountToUpdate.add(new Account(Id=a.Id, Calc_Physicians__c = a.Contacts.size())); } update AccountToUpdate; }
Aggregate queries have a maximum number of rows supported. The reason this works in sandbox but not in production for you is likely because your data set is much larger in your production org than in your sandbox org.
Thanks dkador, only problem is even if I add more filtering, it will still error at 200, which is not the max.