Can I use SalesforceDX to load data into sandboxes?

The short answer is: yes. All of the commands in the force:data command namespace work on any edition of Salesforce any org (provided API is enabled on that org).

The long answer is: it depends on what you need as far as data.

The full command list is as follows:

➜  ~ sfdx force:data
Usage: sfdx force:data:COMMAND [command-specific-options]

manipulate records in your org

sfdx force:data commands: (get help with sfdx help force:data:COMMAND)
 force:data:bulk:delete    bulk delete records from a csv file
 force:data:bulk:status    view the status of a bulk data load job or batch
 force:data:bulk:upsert    bulk upsert records from a CSV file
 force:data:record:create  create a record
 force:data:record:delete  delete a record
 force:data:record:get     view a record
 force:data:record:update  update a record
 force:data:soql:query     execute a SOQL query
 force:data:tree:export    export data from an org into sObject tree format for
                       force:data:tree:import consumption
 force:data:tree:import    import data into an org using SObject Tree Save API

The tree commands are super useful for data with complex relationships. The tree:export will give you a tree structure that should pretty seamlessly be able to be imported (relationships and all) with tree:import.

The consideration to be aware of here is that tree:import is a wrapper for the REST composite/tree API functionality, which has a limit of 200 records maximum (inclusive across all hierarchies imported per transaction). So large numbers of records are not really practical, unless you do some work to break up batches into multiple calls.

For larger data sets or data in CSV format, you can certainly use the bulk API calls, which will get you lots of data, but you don't have the ease of the relationship reference tokens that tree:import gives you.

For simply inserting a single record (say to test a trigger or platform event) you also have the record:create/delete/update commands.

Also, don't forget the ability to easily execute anonymous apex from the Salesforce CLI. Again here, you can do this against any org for which your user has Author Apex perms. If it is just test data sets not based in anything real, consider writing an Apex script and saving it locally, which you can then execute with

> sfdx force:apex:execute -u MyAlias -f MyApexFileScript.apxs

Very few commands in the Salesforce CLI are only for scratch orgs. The bulk of them will give you handy tools to work with any org (although, as always, beware of interacting directly with your production org!)


You also can take a look at the SFDX plugin called SFDX-Data-Move-Utility. I took part in development of this plugin, which is hosted in the forcedotcom GitHub account under the BSD 3-Clause license type. This tool can be very handy for loading the data from another org or from .csv files.

The main advantages of this tool:

  • It can transfer or load multiple sobjects in a single task without your interaction.
  • It can process multiple SObject types preserving relationships between them. Even circular references are supported. This will save time when you have to transfer complex data model with many objects and a lot of lookups between objects.
  • There is no size limitation on your data sets. No workaround needed to transfer big data as when you working with tree:import.
  • With this tool you can also make direct org-to-org data transfer without intermediate .csv files.
  • There is native support for transferring person accounts/contacts and record type.
  • The tool provides option to customize field mapping between the Source and the Target.
  • There is built in support of data anonymization if you want to mask sensitive production data while transferring.
  • The tool is fully configurable with simple JSON file.