Rob on Salesforce
Extract Salesforce Field Details to a Spreadsheet with SFDX

At some point in every Salesforce project, a need arises to export the details of fields to a spreadsheet.

Example output spreadsheet

This can help:

  • Share field details with stakeholders
  • Map fields for migrations and integrations
  • Document what’s in the org

If you need to extract a spreadsheet of fields from your org, you have several options. Each has drawbacks:

Here’s an alternative, inspired by a StackExchange post on the subject. The output is less pretty than the options above, but it offers a functional solution to the problem.

In the SFDX CLI, run the following:

sfdx force:data:soql:query -u my-user-alias -r "csv" -q "SELECT EntityDefinition.QualifiedApiName, Label, DeveloperName, DataType FROM FieldDefinition WHERE EntityDefinition.QualifiedApiName IN ('Account', 'Contact', 'Case') ORDER BY Label ASC" > C:\fields.csv

Explanation:

  • sfdx force:data:soql:query tells the SFDX CLI to perform a SOQL query; see docs
  • -u my-user-alias tells the SFDX CLI which user alias to use
  • -r "csv" uses comma-separated values (CSV) for the output
  • -q "SELECT ..." queries the FieldDefinition object; note the EntityDefinition filter is required
  • > C:\fields.csv saves the output to the given path on your computer

There you have it! A simple way to extract a list of fields from given objects, without having to use third-party apps or websites.


Last modified on 2021-07-06