SOQL SELECT ALL fields is requiers some planning when working with Salesforce Object Query Language (SOQL). Often you need to retrieve all fields from a Salesforce object. Unlike SQL, SOQL does not support the traditional SELECT *
syntax to fetch all columns from an object. However, there are workarounds to achieve this efficiently.
In this guide, we’ll explore how to retrieve all fields in SOQL, why Salesforce does not support SELECT *
, and the best practices for handling queries dynamically.
How to SELECT All Fields in SOQL
Although SOQL does not support SELECT *, you can retrieve all fields dynamically using two primary methods:
Use FIELDS(ALL) (Supported in API Versions 51.0+)
Since API version 51.0, Salesforce introduced the FIELDS() function, which allows retrieving all fields dynamically:
SELECT FIELDS(ALL) FROM Account
Variants of FIELDS()
FIELDS(ALL)
: Retrieves all fields available on the object.FIELDS(STANDARD)
: Retrieves only standard fields.FIELDS(CUSTOM)
: Retrieves only custom fields.
Limitations
- You cannot use
FIELDS(ALL)
withWHERE
,GROUP BY
, orORDER BY
clauses. - It works only in API-based queries (e.g., through Workbench, Postman, or Apex SOQL queries). It does not work in Apex code directly.
Enjoy this article?
Check out our Master SOQL for Salesforce blog