At some point in every Salesforce project, a need arises to export the details of fields to a 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:
- AppExchange apps like Field Dumper (free)
- Usually require vendor assessments, security reviews, and may incur cost
- Third-party sites like Salesforce Schema Lister and D-Feldt Describe
- Need to connect to your org, which represents a security risk
- Create a custom solution with the Apex Schema class or the sObject Describe REST API
- Can involve significant effort; violates the buy-before-build principle
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
sfdx force:data:soql:querytells the SFDX CLI to perform a SOQL query; see docs
-u my-user-aliastells 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.csvsaves 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