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:


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
    Commented Jan 23, 2018 at 17:20
  • @glls updated the post!
    – Anee
    Commented Jan 24, 2018 at 4:47

1 Answer 1


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.


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!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .