Loading

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

게시 일자: Oct 13, 2022
상세 설명

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.

솔루션

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)
Knowledge 기사 번호

000384953

 
로드 중
Salesforce Help | Article