How to get all field names of an object in Salesforce

What We’ll Cover

  1. How to get all fields returned for an object using SOQL
  1. Limitations and variations to get just custom or standard fields
  1. Sample and free tool to pull this automatically
  1. Pushing all your data into a spreadsheet (excel or google sheets)

Get all Fields from a Salesforce Object

Normally you’d use the following pattern when requesting data from Salesforce using SOQL:
SELECT fields FROM object WHERE conditions
for example to get all the names and emails of your contacts you’d use:
SELECT Name, Email FROM contact

It’s Hard to know all the Field Names

  • You could go into the salesforce admin view and look at the objects to see all the custom and standard field names but that’s a pain
  • Better if you could just get them all back

Fields() Function to get all the Salesforce Fields

This is where the fields() function comes in handy. You can use it where you’d normally specify the fields in the query
The fields function takes 3 values as a parameter:
  • ALL - Returns all the fields in the object (custom and standard)
  • STANDARD - Returns just the standard fields (none of the custom fields)
  • CUSTOM - Returns just the custom fields
For example if we want to get all the fields for our contacts we’d use:
SELECT fields(ALL) FROM contact
Careful though if you send this request as is you’ll get the following error: The SOQL FIELDS function must have a LIMIT of at most 200
We need to limit the query to only return at most 200 fields, so:
SELECT fields(ALL) FROM contact limit 200

Try it Out

Here’s a free to use console to try out the SOQL query using your account, just Oauth your SF account and give it a go:

Preview

Expand nested data, rename and delete columns

Column 1
Column 2
Column 3
Column 4
Column 5
     
     
     

Get a live Google Sheet

Export your data to a google sheet, with the SyncWith Addon, or download to CSV

Automatically updated

Add data sources

Build reports & dashboards

Problems with Salesforce Developer Console

If you’re doing this to get a list of fields and using the Salesforce Developer console it’s not a great user experience, kinda hard to read the column names:
notion image
To make it easier to get all the field names of an object in Salesforce using SOQL we made a helper spreadsheet.

Getting an list of fields from the Salesforce Object Schema

Say you want to get more details about the object and it’s fields back, Salesforce has a rest API endpoint to do this, here’s an example of what you can get when calling that endpoint:

Get Schema

Please fill in any necessary fields and click Run.

GET

Preview

View the API data, get a live Google Sheet dashboard

compoundFieldName
custom
defaultValue
defaultedOnCreate
deprecatedAndHidden
extraTypeInfo
label
length
name
relationshipName
type
unique
            
            
            

Get a live Google Sheet

Export your data to a google sheet, with the SyncWith Addon, or download to CSV

Automatically updated

Add data sources

Build reports & dashboards

Spreadsheet that returns the fields for any Salesforce Object

We put together a quick spreadsheet that does the following:
  • returns all the fields in a list format for any salesforce object
  • lets you select the ones you want and generates a CSV so you can easily change your SQL query to only include the relevant ones

Try the spreadsheet

  • Make a copy - you’ll be prompted to install the addon
  • Use the field finder and add new connections to pull more salesforce data into Google Sheets

Other Popular Salesforce Content for Salesforce Develeopers