data export tree
Export data from an org into one or more JSON files.
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).
force:data:tree:export
| Flag Name (Long) | Flag Name (Short) | Description |
|---|---|---|
‑‑api‑version | N/A | Type: Value Override the api version used for api requests made by this command |
‑‑flags‑dir | N/A | Type: Value Import flag values from a directory. |
‑‑json | N/A | Type: Boolean Format output as json. |
‑‑output‑dir | ‑d | Type: Value Directory in which to generate the JSON files; default is current directory. |
‑‑plan | ‑p | Type: Boolean Generate multiple sObject tree files and a plan definition file for aggregated import. |
‑‑prefix | ‑x | Type: Value Prefix of generated files. |
‑‑query | ‑q | Type: Value Required SOQL query, or filepath of a file that contains the query, to retrieve records. |
‑‑target‑org | ‑o | Type: Value Required Username or alias of the target org. Not required if the target-org configuration variable is already set. |
Export records retrieved with the specified SOQL query into a single JSON file in the current directory; the command uses your default org:
Export data using a SOQL query in the “query.txt” file and generate JSON files for each object and a plan that aggregates them:
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”: