When a SOQL query exceeds the 100,000-character limit, Salesforce returns the following error:
"QUERY_TOO_COMPLICATED: Query is either selecting too many fields or the filter conditions are too complicated."
This error can also cause a Lightning Experience record page layout to fail with: "We couldn't find the record you're trying to access. It may have been deleted by another user, or there may have been a system error."
The character limit can be reached in the following scenarios:
This article explains how to reduce SOQL query complexity to resolve the QUERY_TOO_COMPLICATED error.
Formula fields are the most common cause of this error. At query runtime, Salesforce expands formula field logic into the generated SQL, which can dramatically increase the character count. Remove formula fields from the SOQL query and retrieve only non-formula fields. Use trial and error to identify which specific formula fields are pushing the query over the limit.
Each field included in the query contributes its API name to the total character count. Shortening the API names of frequently queried fields reduces the overall query size. This is particularly impactful for currency fields, where the API name length is effectively doubled due to the format method Salesforce must add.
If the error is caused by an auto-generated SOQL on a Lightning Experience record page layout (no custom SOQL involved), reduce the number of fields displayed on the page layout. Layouts with more than approximately 250 fields are most at risk. Remove fields that are not regularly used or move them to a secondary section.
000386662

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.