Loading

Maximum length for SOQL statements

Publiseringsdato: May 8, 2026
Beskrivelse

The maximum length for a SOQL (Salesforce Object Query Language) statement is 100,000 characters. This is a hard limit enforced by Salesforce to ensure platform stability and performance. This limit cannot be increased by customers; adjustments can only be made by Salesforce Product Management at their discretion.

You may encounter this limit when constructing SOQL queries with many fields, complex formulas, or large numbers of currency fields. 

Common causes of reaching the character limit or triggering QUERY_TOO_COMPLICATED include:

  • 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 100,000 character limit. To avoid this error, reduce the complexity of your SOQL statement.

  • Page layouts in Lightning with more than 250 fields can also cause a QUERY_TOO_COMPLICATED error. Lightning uses auto-generated SOQL to retrieve fields for a record page layout, so the error can occur even if there isn’t any customer-written SOQL.

  • The character limit can also be reached by including too many currency fields. Currency fields require SOQL to use a format method, roughly doubling the field API name length for each currency field.


 

Løsning

Split the Query into Multiple Smaller Queries

Divide the single large query into multiple queries that each retrieve a smaller subset of fields. 

Reduce Formula Field Complexity

Formula fields are expanded internally when Salesforce processes a SOQL statement. A query that appears to be within the 100,000 character limit may exceed it after formula expansion. Remove formula fields from the SOQL query where possible, or calculate formula values in Apex code rather than querying them directly.

Reduce Currency Fields in the Query

Each currency field causes Salesforce to internally use a format() method, which roughly doubles the length contributed by that field to the query. Reduce the number of currency fields included in a single query. Split currency field retrieval into a separate query if necessary.

Optimize Lightning Page Layouts

If the QUERY_TOO_COMPLICATED error occurs on a Lightning record page without any custom SOQL, the issue is likely caused by the number of fields on the page layout. Lightning Experience auto-generates SOQL to retrieve fields for record pages. Reduce the number of fields on the page layout to fewer than 250 fields.

Knowledge-artikkelnummer

000386440

 
Laster
Salesforce Help | Article