Newer Version Available
Example: Export and Import Data Between Orgs
- Created the Broker and Properties custom objects by pushing the DreamHouse source.
- Assigned the permission set.
- Populated the objects with the data.
See the README in the dreamhouse-lwc GitHub repo for instructions on these prerequisite tasks.
-
Export the data from the org-with-data scratch
org.
Use the force:data:soql:query command to fine-tune the SELECT query so that it returns the exact set of data you want to export. This command outputs the results to your terminal or command window, but it doesn’t generate any files.
1sfdx force:data:soql:query -u org-with-data --query \ 2 "SELECT Id, Name, Title__c, Phone__c, Mobile_Phone__c, \ 3 Email__c, Picture__c, \ 4 (SELECT Name, Address__c, City__c, State__c, Zip__c, \ 5 Price__c, Beds__c, Baths__c, Picture__c, \ 6 Thumbnail__c, Description__c \ 7 FROM Properties__r) \ 8 FROM Broker__c" -
When you’re satisfied with the SELECT statement, use it to export the data into a set
of JSON files.
1sfdx force:data:tree:export -u org-with-data --query \ 2 "SELECT Id, Name, Title__c, Phone__c, Mobile_Phone__c, \ 3 Email__c, Picture__c, \ 4 (SELECT Name, Address__c, City__c, State__c, Zip__c, \ 5 Price__c, Beds__c, Baths__c, Picture__c, \ 6 Thumbnail__c, Description__c \ 7 FROM Properties__r) \ 8 FROM Broker__c" \ 9 --prefix export-demo --outputdir sfdx-out --planThe export command writes the JSON files to the sfdx-out directory and prefixes each file name with the string export-demo. The files include a plan definition file, which refers to the other files that contain the data, one for each exported object (Broker and Properties).
-
Import the data into the org-needs-data scratch
org by specifying the plan definition file.
1sfdx force:data:tree:import -u org-needs-data \ 2 --plan sfdx-out/export-demo-Broker__c-Property__c-plan.jsonUse the --plan parameter to specify the full path name of the plan execution file generated by the force:data:tree:export command. Plan execution file names always end in -plan.json.
Example
Looking for a more complicated example? The easy-spaces-lwc sample app has a data plan showing how to import Accounts, related Contacts, and a 3-level deep custom object chain.