Salesforce has introduced SOQL Fields functions. This new function lets us query all the Salesforce fields of the object, Before you would have to add various fields api names to the select to get their values
You can include any of these in the field list:
- FIELDS(ALL) — select all the fields of an object.
- FIELDS(CUSTOM) — select all the custom fields of an object.
- FIELDS(STANDARD) — select all the standard fields of an object
Usage
You can use FIELDS() as the complete field list. For example:
SELECT FIELDS(ALL) FROM Account LIMIT 200
SELECT FIELDS(CUSTOM) FROM Account LIMIT 200
SELECT FIELDS(STANDARD) FROM Account LIMIT 200
The FIELDS() keyword can also be used in subqueries
SELECT
Account.Name,
(SELECT FIELDS(ALL) FROM Account.Contacts LIMIT 200)
FROM Account
The API returns an error if the SELECT statement results in any duplicated field names. For example, this query:
SELECT Id, FIELDS(ALL) FROM User LIMIT 200
Bounded and Unbounded Queries
The API distinguishes bounded queries, which have well-defined sets of fields, from unbounded queries, which have sets of fields that the API can’t determine in advance. For example, because the number of custom fields for an object isn’t predetermined, FIELDS(CUSTOM) and FIELDS(ALL) are considered unbounded. This table shows the support for FIELDS() in bounded and unbounded queries:
