Question or Problem

You see the following error when viewing the standard Opportunity Line Items (Opplineitem object) data set in both the Template Builder and View Data workbook from a button on the opportunity object: QUERY TOO COMPLICATED - Query is either selecting too many fields or the filter conditions are too complicated.

Causes or Possible Causes

Long, complex SOQL statements, such as statements that contain many formula fields, can sometimes result in a QUERY_TOO_COMPLICATED error. The error occurs because the statement is expanded internally when processed by Salesforce, even though the original SOQL statement is under the 20,000 character limit. To avoid this, reduce the complexity of your SOQL statement.

When Composer performs queries on Opportunity Line Items, 3 objects are retrieved:

  1. OpportunityLineItem
  2. OpportunityLineItem.PricebookEntry
  3. OpportunityLineItem.PricebookEntry.Product2

The resulting query exceeds the 20,000 bytes and the query fails due to the excessive number of custom fields. For more information, see the Salesforce documentation for SOQL limits: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select.htm