Import and Export Records using Salesforce DX

Using Salesforce DX to Export and Import records into regular Salesforce Instances without dependency on developer hub org

Import and Export Records using SalesforceDx

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
Import Export Data Using Salesforce DX
Import Export Data 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

-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

-f : JSON file to be imported
-u : Salesforce user to perform operation

Related posts