Skip to main content

How to Export All Salesforce Objects and Fields to a CSV File

Whether you are planning a massive data migration, cleaning up technical debt, or preparing for a compliance audit, you need a clear map of your Salesforce architecture. Manually clicking through the Object Manager to document hundreds of fields is a mind-numbing and time-consuming process. Thankfully, you can easily export your entire schema directly into a CSV spreadsheet to create a comprehensive data dictionary.

In plain words: Exporting your Salesforce objects and fields to a CSV file creates an offline "data dictionary." This spreadsheet gives you an instant overview of every field's API name, data type, length, and custom status without having to dig through the Salesforce Setup menu.

Key Points Summary

  • Creating a data dictionary is essential for org cleanups, system audits, and integration mapping.
  • The modern, fastest way to extract field data is by querying the FieldDefinition object using the Tooling API.
  • Free browser extensions like Salesforce Inspector Reloaded make exporting schema to Excel or CSV a one-click process.
  • Developers can leverage the updated Salesforce CLI (sf commands) to pull object metadata automatically.

Why Create an Offline Salesforce Data Dictionary?

Having a complete spreadsheet that maps out your Salesforce schema is incredibly valuable for several reasons:

  • Data Migration & Integrations: Easily map source data to Salesforce target fields when using tools like Data Loader, MuleSoft, or custom APIs.
  • System Auditing & Cleanup: Spot unused, redundant, or orphaned custom fields that are cluttering your org and holding you back from clean deployments.
  • Compliance & Governance: Maintain a snapshot of where sensitive data (like GDPR, HIPAA, or PII) lives across your objects.
  • Stakeholder Documentation: Quickly hand over an up-to-date schema reference to external consultants, business analysts, or new developers.

Method 1: The Modern Way (SOQL & Tooling API)

Instead of writing complex Apex loops, you can now query Salesforce's metadata directly using the Tooling API. You can run this simple query in the Developer Console Query Editor (check the "Use Tooling API" box at the bottom) or via Salesforce Inspector.

Real-Life Example: Tooling API Query
Run this query to instantly extract all fields on the Account object. You can then copy the results straight into a spreadsheet.
SELECT QualifiedApiName, DeveloperName, DataType, Length 
FROM FieldDefinition 
WHERE EntityDefinition.QualifiedApiName = 'Account'

Method 2: Use Modern Free Browser Tools

For admins who want a purely point-and-click experience across the entire org, dedicated schema tools are the best route. They handle the heavy lifting behind the scenes.

  • Salesforce Inspector Reloaded: This free Chrome extension is the holy grail for Salesforce pros. Navigate to its "Data Export" tab and run the query above, or use its built-in schema explorer to copy field definitions straight to Excel.
  • Salesforce Schema Builder: While native to Salesforce and great for visual mapping, it doesn't export to CSV easily. Use it for visualizing relationships, but stick to data tools for spreadsheet exports.

Method 3: Export Object Schema via Anonymous Apex

If you prefer a built-in programmatic solution, you can run a script in the Developer Console to extract object and field metadata directly to your debug logs.

// Define the object you want to export
String objectName = 'Account'; 

Map<String, Schema.SObjectField> fieldMap = Schema.getGlobalDescribe().get(objectName).getDescribe().fields.getMap();

System.debug('Field Label,API Name,Data Type,Length');
for (Schema.SObjectField field : fieldMap.values()) {
    Schema.DescribeFieldResult fieldDescribe = field.getDescribe();
    System.debug(
        fieldDescribe.getLabel() + ',' +
        fieldDescribe.getName() + ',' +
        fieldDescribe.getType() + ',' +
        fieldDescribe.getLength()
    );
}

Once the script finishes, check the Debug Only box in your log panel, copy the comma-separated output, and paste it into a .csv file.

Method 4: The Salesforce CLI (sf)

If you are a developer using VS Code, you can use the modern Salesforce CLI (sf) to pull object definitions directly into your terminal. This is perfect for automating documentation.

sf sobject describe --sobject Account

This command returns a highly detailed JSON structure of the object, which you can easily parse into a CSV using a simple Python or Node.js script.

Common Pitfalls to Avoid:
  • Governor Limit Exhaustion in Apex: Running Schema.getGlobalDescribe() across all objects at the same time in Apex will likely hit CPU time limits or heap size errors. Export objects one by one, or use the SOQL Tooling API method.
  • Field-Level Security (FLS) Hidden Fields: API extensions and SOQL queries respect the logged-in user's profile permissions. If your profile doesn't have Read access to a field, it won't show up in your export! Always run these exports logged in as a System Administrator.

Frequently Asked Questions (FAQ)

Q: Can I export all fields for all objects at once?

A: Doing this via Apex or SOQL usually hits system limits because enterprise orgs have thousands of fields. Your best bet for a full-org export is using third-party AppExchange apps (like Config Workbook) or writing a script using the Salesforce CLI that iterates through objects one by one.

Q: Does the native Salesforce "Data Export" tool include schema data?

A: No. The weekly Data Export service in Setup only exports the actual record data (the rows), not the metadata or schema definitions (the columns).

Q: Can I get picklist values in my export?

A: Yes! If you use the Anonymous Apex method, you can add fieldDescribe.getPicklistValues() to your debug loop. Just be aware that fields with hundreds of picklist values can make your CSV output messy.

Documentation Rule of Thumb: Regenerate your CSV data dictionary after every major sandbox deployment or quarterly Salesforce release to ensure your documentation stays perfectly in sync with production.
360 Summary Card
  • Core Concept: Extracting Object & Field Metadata to CSV/Excel.
  • Best Use Cases: Creating a Data Dictionary, Org Audits, API Integration Mapping.
  • Top Recommended Tools: SOQL Tooling API, Salesforce Inspector Reloaded, Salesforce CLI (sf).
  • Data Points Captured: Field Labels, API Names, Data Types, Field Lengths, and Custom/Standard status.