data export bulk

Bulk export records from an org into a file using a SOQL query. Uses Bulk API 2.0.

You can use this command to export millions of records from an org, either to migrate data or to back it up.

Use a SOQL query to specify the fields of a standard or custom object that you want to export. Specify the SOQL query either at the command line with the –query flag or read it from a file with the –query-file flag; you can’t specify both flags. The –output-file flag is required, which means you can only write the records to a file, in either CSV or JSON format.

Bulk exports can take a while, depending on how many records are returned by the SOQL query. If the command times out, the command displays the job ID. To see the status and get the results of the job, run “sf data export resume” and pass the job ID to the –job-id flag.

IMPORTANT: This command uses Bulk API 2.0, which limits the type of SOQL queries you can run. For example, you can’t use aggregate functions such as count(). For the complete list of limitations, see the “SOQL Considerations” section in the “Bulk API 2.0 and Bulk API Developer Guide” (https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/queries.htm).

Flag Name (Long)Flag Name (Short)Description
‑‑all‑rowsN/AType: Boolean

Include records that have been soft-deleted due to a merge or delete. By default, deleted records are not returned.
‑‑api‑versionN/AType: Value

Override the api version used for api requests made by this command
‑‑column‑delimiterN/AType: Value
Valid Values: BACKQUOTE, CARET, COMMA, PIPE, SEMICOLON, TAB

Column delimiter to be used when writing CSV output. Default is COMMA.
‑‑flags‑dirN/AType: Value

Import flag values from a directory.
‑‑jsonN/AType: Boolean

Format output as json.
‑‑line‑endingN/AType: Value
Valid Values: LF, CRLF

Line ending to be used when writing CSV output. Default value on Windows is is CRLF; on macOS and Linux it’s LR.
‑‑output‑fileN/AType: Value
Required

File where records are written.
‑‑query‑qType: Value

SOQL query to execute.
‑‑query‑fileN/AType: Value

File that contains the SOQL query.
‑‑result‑format‑rType: Value
Required
Valid Values: csv, json
Default value: csv

Format to write the results.
‑‑target‑org‑oType: Value
Required

Username or alias of the target org. Not required if the target-org configuration variable is already set.
‑‑wait‑wType: Value

Time to wait for the command to finish, in minutes.

Export the Id, Name, and Account.Name fields of the Contact object into a CSV-formatted file; if the export doesn’t complete in 10 minutes, the command ends and displays a job ID. Use the org with alias “my-scratch”:

Similar to previous example, but use the default org, export the records into a JSON-formatted file, and include records that have been soft deleted: