TransWikia.com

Push & pull data with sfdx commands

Salesforce Asked by Anee on December 26, 2021

We were trying to export & import data from a sandbox using the sfdx tree export command.

Even after going through the different links on google I could not understand how will we export a sObject which has lookup in it? Below mentioned is one of those links:

https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_test_data_example.htm

I know we can write sub SOQL queries and create a plan to retrieve all the references an object has, but when I tried creating a plan with a lookup field I started getting errors. Below is the command I tried:

sfdx force:data:tree:export “SELECT Id,CreatedById FROM Product2” -d ./data -p

What’s the right way to import and export data using the above commands? I have close to 2000 records under the Product2.

One Answer

Im assuming that you when you say that you want to export data from a sandbox that you mean a scratch org. If not then I dont think that command will work.

If you do mean a sandbox then I would try a few thing. First what is your default target org? If it is not the org which you are trying to export data from then you will need to use the -u flag to specify the target username.

EX)

sfdx force:data:tree:export “SELECT Id,CreatedById FROM Product2” -u myorg -d ./data -p

I used https://developer.salesforce.com/blogs/developer-relations/2017/07/migrating-existing-projects-salesforce-dx.html for reference when I started using sfdx. This blog post has examples of exporting and importing data to/from a scratch org. Hope one of this does the trick!

Answered by Zack Walton on December 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP