Loading

SOQL Error 'QUERY_TOO_COMPLICATED' — Causes and Resolutions

Publiceringsdatum: May 29, 2026
Beskrivning

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:

  • Complex formula fields: Formula fields that appear simple in SOQL can expand significantly when Salesforce generates the underlying SQL. Multiple complex formula fields used together can push the query over the limit.
  • Large page layouts: Lightning Experience uses auto-generated SOQL to retrieve all fields displayed on a record page layout. A layout with more than approximately 250 fields can trigger this error even without any custom-written SOQL.
  • Currency fields: Each currency field in the SOQL query requires Salesforce to add a format method, which adds at least twice the length of the field's API name to the query character count.
Lösning

This article explains how to reduce SOQL query complexity to resolve the QUERY_TOO_COMPLICATED error.

Step 1: Remove Formula Fields from the Query

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.

Step 2: Shorten Field API Names

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.

Step 3: Reduce the Number of Fields on the Page Layout

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.

Knowledge-artikelnummer

000386662

 
Laddar
Salesforce Help | Article