Skip to content Skip to main navigation Skip to footer

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

Full Error Message: “Error while creating new document. Error message: Aggregate query has too many rows for direct assignment, use FOR loop”

This error may happen when generating a document that has hit a limit with related list items. A limitation could be reached with a combination of the related list tables and long text fields from a specific record. There are many variables as to why a document could time out and this error to be caused so it may take some trial and error to see how to resolve.

To troubleshoot this error message:

  1. First, see if this error is happening on one record or multiple records that have different amounts of related list items. Can try to generate document from a record with less related list items and see if error persists.
  2. If using a long text field in your template: you may be able to resolve this too many rows/timeout error by reducing the value of characters in this long text field.
  3. If issue is trying to merge too many related list items into the document, you can somehow split up the related list by using the filter feature in template builder: https://kb.opero.com/documents/knowledge-base/template-configuration/
  4. You can try to isolate which related list merge field is returning the error message  by decoding different related list merge fields. For example in your document you may have a related list merge field that looks like {!Opportunity.r.OpportunityLineItems.Quantity} and to “decode” it temporarily to isolate where the error is coming from, you can just remove the first bracket so it becomes !Opportunity.r.OpportunityLineItems.Quantity}. You can do this one by one to see which of the merge fields is causing the error and go from there. Or paste these fields alone in a new google doc template so you can be sure no hidden formatting that could cause it to time out.
  5. Make sure have latest Opero Documents package installed from AppExchange.
  6. If you have done above steps and error persists, you may have found an app limitation with amount of related list fields combined with long text area fields, see example below.

Example Limitations found on combination of the related list tables and long text fields is hitting a limit:

-When I recreate the related lists only, there is no error, even with related lists on two separate child records
-When I add a single 2000-character long text field to the template along with the related list tables, there is no error.
-When I add two long text fields (2000 char + 32000 char Campaign Description field, length not customizable) to the template along with the related list tables, I get the “Aggregate query has too many rows for direct assignment, use FOR loop” error.

So in sum, the error happens when there is a combination of the related list tables and long text fields that is hitting a limit.