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.

To troubleshoot this error message:

  1. 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.
  2. 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.
  3. 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.
  4. 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: http://kb.a5documents.com/knowledge-base/merge-related-list-into-a-table/.
  5. 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.
  6. Make sure have latest A5 Documents package installed from AppExchange.
  7. 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.