Data export Salesforce DX command

The data export command allows exporting a dataset from a scratch Org into JSON files.

Let's try to export the dataset to the data folder in your local project from one of the Dev Orgs. Note that you will need to connect your CLI with the Org you are trying to export data into using the auth commands we discussed in the previous section.

Let's try and run the following command:

sfdx force:data:tree:export -p -q "SELECT Id, Name, (SELECT Id, LastName, FirstName FROM Contacts) FROM Account" -u MyTPO --outputdir./data

Note that, here, -u is followed by the Org alias. It can be a username as well of the Org. In this case, I have an Org with the alias MyTPO.

-p indicates that multiple subject files should be generated, followed by the automatic generation of plan file definitions.

The preceding command exports the data using the Salesforce Object Query Language (SOQL) into an output directory data in the root folder. Remember to run this command from the root of your project.

The preceding command creates a folder named data with the following file structure:

Observe the structure of all the files that were generated here.

A couple of things you can infer from the JSON files are as follows:

  • A referenceId is self-generated for both contact and account files.
  • The plan file maps which objects should have the saved Refs and which ones should be resolved. The sample plan file would look like the following for the Account and Contact objects in Salesforce:
[{
"sobject": "Account",
"saveRefs": true,
"resolveRefs": false,
"files": [
"Accounts.json"
]
},
{
"sobject": "Contact",
"saveRefs": false,
"resolveRefs": true,
"files": [
"Contacts.json"
]
}
]
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.163.62