Import and Export Records using SalesforceDx

Import and Export Records using Salesforce DX

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


7 responses to “Import and Export Records using Salesforce DX”

  1. nithesh1992 Avatar

    Is there anyway we can retain the parent-child relationship while exporting and importing the records through sfdx??

    1. Manjunadh Manubolu Avatar
      Manjunadh Manubolu

      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

  2. Dibakar Sahoo Avatar
    Dibakar Sahoo

    “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”

  3. Alekh Sharma Avatar
    Alekh Sharma

    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

    1. Alekh Sharma Avatar
      Alekh Sharma


  4. UG Avatar

    has anyone ran into a an error: The requested resource does not exist.
    when running sfdx force:data:tree:import?

  5. Aarush verma Avatar

    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.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading