Newer Version Available

This content describes an older version of this product. View Latest

Ways to Add Data to Your Org

Orgs for development need a small set of stock data for testing.

Sometimes, the stock data in a scratch org 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 probably don’t need to worry 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 datasets 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 data query CLI command to run a SOQL query against an 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’re 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.

data export | import tree Commands

The SObject Tree Save API drives the data export|import tree commands for exporting and importing data. The commands use JSON files to describe objects and relationships. The data 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 data import command loads parents and children already in the hierarchy.

These commands are intended for developers to test with small datasets. The query for export can return a maximum of 2000 records. The files for import can have a maximum of 200 records.

Note

data delete | upsert bulk Commands

Bulk API 2.0 drives the data delete|upsert bulk commands for exporting a basic dataset 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 data delete|upsert 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.

data create | delete | get 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 data create|delete|get record commands. No data files are needed.