Newer Version Available
Ways to Add Data to Your Org
Sometimes, the stock data doesn’t meet your development needs. Apex tests generally create their own data. Therefore, if Apex tests are the only tests you’re running in a scratch org, you can probably forget about data for the time being. However, other tests, such as UI, API, or user acceptance tests, do need baseline data. Make sure that you use consistent data sets when you run tests of each type.
The following sections describe the Salesforce CLI commands you can use to populate your orgs. The commands you use depend on your current stage of development.
You can also use the force:data:soql:query CLI command to run a SOQL query against a scratch org. While the command doesn’t change the data in an org, it’s useful for searching or counting the data. You can also use it with other data manipulation commands. See the SOQL and SOSL Reference Guide for general SOQL limits that also apply when you use these commands.
Considerations for Scratch Orgs
Scratch orgs come with the same set of data as the edition on which they are based. For example, Developer Edition orgs typically include 10–15 records for key standard objects, such as Account, Contact, and Lead. These records come in handy when you’re testing something like a new trigger, workflow rule, Lightning web component, Aura component, or Visualforce page.
force:data:tree Commands
The SObject Tree Save API drives the force:data:tree commands for exporting and importing data. The commands use JSON files to describe objects and relationships. The export command requires a SOQL query to select the data in an org that it writes to the JSON files. Rather than loading all records of each type and establishing relationships, the import command loads parents and children already in the hierarchy.
force:data:bulk Commands
Bulk API drives the force:bulk commands for exporting a basic data set from an org and storing that data in source control. You can then update or augment the data directly rather than in the org from where it came. The force:data:bulk commands use CSV files to import data files into scratch orgs or to delete sets of data that you no longer want hanging around. Use dot notation to establish child-to-parent relationships.
force:data:record Commands
Everyone’s process is unique, and you don’t always need the same data as your teammates. When you want to create, modify, or delete individual records quickly, use the force:data:record:create|delete|get|update commands. No data files are needed.