Salesforce introduced one of its most powerful and developer-friendly features in Winter ’23: the FIELDS() function in SOQL.
This feature completely changes how we write queries—especially for debugging, API testing, dynamic data exploration, and admin/developer productivity.
Before this feature, retrieving “all fields” from an object required:
-
manually listing every field
-
generating describe calls
-
writing dynamic SOQL
-
using tool-generated queries (Workbench, VS Code, etc.)
Now, with FIELDS(), you can retrieve standard fields, custom fields, or ALL fields in one line. Click here to watch video on how it works
What is the FIELDS() Function?
FIELDS() is a SOQL function that dynamically expands into the fields of an SObject at query runtime.
It supports three modes:
| Mode | Description |
|---|---|
FIELDS(STANDARD) | Retrieves all standard fields of the object. |
FIELDS(CUSTOM) | Retrieves only the custom fields (fields ending in __c). |
FIELDS(ALL) | Retrieves both standard + custom fields. |
Why Is FIELDS() So Useful?
✔ Saves time — no need to list 50+ fields
✔ Perfect for debugging
✔ Removes need for dynamic SOQL in many cases
✔ Excellent for API exploration (Postman, Workbench, VS Code)
✔ Helps admins who need quick data visibility
✔ Reduces typing + chance of errors
Basic Syntax
Very simple, but extremely powerful.
Use Case 1: Retrieve ALL Fields from an Object
This is the most popular and practical use case.
Example: Retrieve All Fields From Account
This returns:
-
all standard fields (Name, CreatedDate, OwnerId…)
-
all custom fields (Rating__c, Customer_Segment__c…)
-
formula fields
-
lookup fields
-
address fields
-
system fields
Use Case 2: Retrieve ONLY Standard Fields
Useful when dealing with API integrations, clean datasets, and performance optimization.
Example
This returns only standard fields like:
-
FirstName
-
LastName
-
AccountId
-
Email
-
CreatedDate
-
LastModifiedDate
All custom fields (__c) are excluded.
Use Case 3: Retrieve ONLY Custom Fields
Perfect for:
-
org audits
-
metadata reviews
-
cleaning technical debt
-
understanding customization level
-
analyzing managed package fields
Example
This returns fields like:
-
Region__c
-
Probability_Score__c
-
Is_Renewal__c
-
Product_Code__c
No standard fields are included.
Use Case 4: Debugging Triggers and Apex Code
When you're debugging a trigger or flow that behaves strangely, retrieving all fields helps you verify what’s happening.
Example: Quick Debug Query
This prints the entire Case record—including fields you forgot existed.
Use Case 5: Exploring Data Model of Unknown Objects
Perfect for:
-
newly inherited orgs
-
client orgs
-
managed packages
-
third-party integrations
-
sandboxes with changes
Example: Explore Custom Object Fields
Quickly shows you all customizations related to that object.
Use Case 6: Querying in Developer Console / Workbench / Postman
For API testing:
Great for external system developers who need a full understanding of the schema.
Use Case 7: Exporting Data Fast
Admins who want a quick snapshot can use:
Then export the results—no need to build CSVs manually.
Limitations of FIELDS() You Should Know
Although powerful, FIELDS() has rules:
Not Allowed in Triggers
Triggers require specific field access, not dynamic field enumeration. So this:
cannot be inside trigger context Apex.
Cannot Be Used for Bulk Select
If the object has too many fields, the query might hit SOQL limits.
For example: 500+ fields may exceed query character limits.
Not Usable in Subqueries
This will fail:
Not Accepted in Tooling or Metadata API Queries
It works only in standard SOQL.
Performance Considerations
Using FIELDS(ALL) means:
-
more data transferred
-
more CPU time during serialization
-
larger heap size
-
slower performance in large orgs
Recommendation:
Use FIELDS(STANDARD) or FIELDS(CUSTOM) when possible.
Best Practices
- Use FIELDS() for debugging, not production
- Limit your results
- Always include
LIMIT: - SELECT FIELDS(ALL) FROM Opportunity LIMIT 1
- Always include
LIMIT: - SELECT FIELDS(ALL) FROM Opportunity LIMIT 1

Comments
Post a Comment