Loading

'Aggregate query has too many rows for direct assignment, use FOR loop' Salesforce Error

Data pubblicazione: Oct 13, 2022
Descrizione

Example SOQL Query where the number of Contacts/Account is too large:

Select name, (Select firstname,lastname From Contact) From Account limit 1


This error happens when you're trying to use an aggregate function (like COUNT) on a query that has too many rows.

Risoluzione

To fix the error, remove this condition and use a FOR:
 

for (childtype ch : Parent.children) {

//do some logic...

}

Alternatively, have a map of parent to child objects and get the size of each key from the map.

Example query that can cause the error:

if (parent.child.size() > 0)
Numero articolo Knowledge

000384953

 
Caricamento
Salesforce Help | Article