Until recent years, Salesforce did not allow you to do a Select All fields type statement. As a new lazy developer transitioning to the Salesforce platform I cursed the number of times I had to go to away and get the API name for a set of fields that I wanted to include in a query - when writing code this was fine, but when wanting to debug Production issues, this was a real pain! Overtime I come to appreciate the fact that it made me a better developer, when writing code I only queried the fields I needed, taking advantage of small performance gains by not retrieving hundreds of fields for simple object database operations.

Anyhow, Salesforce has come a long way, and now there is the ability too quickly and easily select all, all custom or all standard fields for an object by using a simple statement in your SOQL queries.

  • FIELDS(ALL)—to select all the fields of an object.
  • FIELDS(CUSTOM)—to select all the custom fields of an object.
  • FIELDS(STANDARD)—to select all the standard fields of an object.

In each case, FIELDS() respects field-level security so it only shows the fields that you have permission to access.


Return all fields for an object

SELECT FIELDS(ALL) FROM Contact WHERE FirstName = 'Connor' LIMIT 250

Return only custom fields for an object

SELECT FIELDS(CUSTOM) FROM Custom_Object__c WHERE Custom_Field__c != NULL LIMIT 250

Nested Query Example

SELECT Opportunity.Name, (SELECT FIELDS(ALL) FROM Opportunity.Quotes LIMIT 200) FROM Opportunity


Remember, if performance is key, and to respect the Salesforce Governor Limits you’ll get better performance by specifying them explicitly rather than using FIELDS() and retrieving more fields than you need.