Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This error occurs when the length of the SOQL statement is too long and fetches a large number of fields. In other words, the query may be too long or complex.

Solution

...

It is best to reduce the complexity of queries. Either reduce the length (characters) of the query or the number of fields it returns.

Salesforce has a set limit on the length of a query to ensure the system runs smoothly. When a query is too long and fetches a large number of fields, the user may hit this limit. Some reasons for this error have to do with the way Salesforce processes queries.

Another reason for this error is Lightning page layouts with more than 250 fields. Salesforce uses queries to get the fields for the layout. For this reason, the QUERY_TOO_COMPLICATED error can arise, even if there are no custom queries.

Finally, the query length can be too long due to using too many currency fields. Currency fields use twice as many characters as other fields and can make queries too long.

For more information, refer to Salesforce Documentation - Maximum length for SOQL statements.