Export data from an org into one or more JSON files.
Description for data export tree
Specify a SOQL query, either directly at the command line or read from a file, to retrieve the data you want to export. The exported data is written to JSON files in sObject tree format, which is a collection of nested, parent-child records with a single root record. Use these JSON files to import data into an org with the "sf data import tree" command.
If your SOQL query references multiple objects, the command generates a single JSON file by default. You can specify the --plan flag to generate separate JSON files for each object and a plan definition file that aggregates them. You then specify just this plan definition file when you import the data into an org.
The SOQL query can return a maximum of 2,000 records. For more information, see the REST API Developer Guide. (https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_composite_sobject_tree.htm).
Aliases for data export tree
force:data:tree:export
Flags
| Flag Name (Long) | Flag Name (Short) | Description |
|---|---|---|
| <code>‑‑api‑version</code> | N/A | Type: Value<br><br>Override the api version used for api requests made by this command |
| <code>‑‑flags‑dir</code> | N/A | Type: Value<br><br>Import flag values from a directory. |
| <code>‑‑json</code> | N/A | Type: Boolean<br><br>Format output as json. |
| <code>‑‑output‑dir</code> | <code>‑d</code> | Type: Value<br><br>Directory in which to generate the JSON files; default is current directory. |
| <code>‑‑plan</code> | <code>‑p</code> | Type: Boolean<br><br>Generate multiple sObject tree files and a plan definition file for aggregated import. |
| <code>‑‑prefix</code> | <code>‑x</code> | Type: Value<br><br>Prefix of generated files. |
| <code>‑‑query</code> | <code>‑q</code> | Type: Value<br>Required<br><br>SOQL query, or filepath of a file that contains the query, to retrieve records. |
| <code>‑‑target‑org</code> | <code>‑o</code> | Type: Value<br>Required<br><br>Username or alias of the target org. Not required if the target-org configuration variable is already set. |
Examples for data export tree
Export records retrieved with the specified SOQL query into a single JSON file in the current directory; the command uses your default org:
sf data export tree --query "SELECT Id, Name, (SELECT Name, Address__c FROM Properties__r) FROM Broker__c"
Export data using a SOQL query in the "query.txt" file and generate JSON files for each object and a plan that aggregates them:
sf data export tree --query query.txt --plan
Prepend "export-demo" before each generated file and generate the files in the "export-out" directory; run the command on the org with alias "my-scratch":
sf data export tree --query query.txt --plan --prefix export-demo --output-dir export-out --target-org my-scratch
<!-- prettier-ignore-end -->