1

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.

  • what "different links on google" ? please update your post accordingly. Thanks – glls Jan 23 '18 at 17:20
  • @glls updated the post! – Anee Jan 24 '18 at 4:47
0

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!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.