In today’s continuous integration solution built for Salesforce, if you need to load sample data into Salesforce then either we use command line dataloader or custom tool built to import export records.
With Salesforce DX, we can import and export records right from Salesforce DX. Again, if you are new to Salesforce DX, then first read this blog post to quickly understand what is Salesforce DX.
We don’t need Developer Hub or Scratch Orgs to use Salesforce DX for import and export. In this blog post, I have used my regular developer org for demo.
First step as always, to make sure if Salesforce DX CLI is connected to your Org or not ? If its not connected then use below command to connect and give alias which is easy to remember.
sfdx force:auth:web:login --setalias jzaa1
Export records using Salesforce DX

Below command can be used to export 10 Account records. We can change this SOQL as per requirement
sfdx force:data:tree:export -q "SELECT Id,Name FROM Account limit 10" -d ./ilovenag -u ilovenagpur@gmail.com
Where
-q : SOQL query
-d : directory, where exported json file can be saved
-u : Salesforce user to perform operation
Import records using Salesforce DX
Use below command to Import records in Salesforce instance, which we just exported in previous step
sfdx force:data:tree:import -f ilovenag/Account.json -u jzaa1
Where
-f : JSON file to be imported
-u : Salesforce user to perform operation
Is there anyway we can retain the parent-child relationship while exporting and importing the records through sfdx??
Yes, it is possible. Example : sfdx force:data:tree:export -q “Select Id,Name,(Select Id,LastName from Contacts) from Account limit 10” -d ./MyAccData -u Manju3
“Hi, I am Dibakar, working in a marketing team. We are looking for a salesforce influencer, who is technically strong and engaged in real paid reviews on salesforce related third party products.
In case, you are interested please send your details like site URL, review links already done, site traffic and price per review. Looking forward for an early response.
Thanks. Dibakar”
Hello sir, I am learning Salesforce DX and CLI is working all the commands except for Export data. The error is ‘is not recognized as an internal or external command’. Tried to many times but still no solution. Your view and knowledge on this issue can be really helpful for you.
Thank you
me*
has anyone ran into a an error: The requested resource does not exist.
when running sfdx force:data:tree:import?
To grow your business and gain profits, Import Export Data would be a great source. It is a great market research tool to analyze market trends and latest scenarios in the industry.