Loading

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

Date de publication: Oct 13, 2022
Description

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.

Résolution

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)
Numéro d’article de la base de connaissances

000384953

 
Chargement
Salesforce Help | Article