System.QueryException: Aggregate query has too many rows for direct assignment, use FOR loop
This exception is talking about an “aggregate query” not an “aggregate function.” I had never heard the term “aggregate query” before, and I suspect you haven’t either. After hunting around, I found the relevant Salesforce documentation – Salesforce Apex Developer Guide: SOQL For Loops. The documentation explains that Salesforce might throw the System.QueryException when a query has a sub-query (this is the “aggregate query”), and our sub-query returns more than 200 child records. For example, if we have an Account with more than 200 AccountTeamMembers, we might get the exception when we run the following code with a query on Account with a sub-query for child AccountTeamMembers. Code that could throw an exception if there are more than 200 child records: List<Account> accounts = [Select Id, (Select Id, AccountId , UserId From AccountTeamMembers) , (Select Id , OwnerId, AccountId from Opportunities) From Account]; for ( Account acc : accounts ) { // Either...