Testing and sandboxes · 5 min read

How to Create Test Data for a Salesforce Sandbox

Published · By Edward Elliott

A new Developer sandbox has your configuration and your users, and no records at all. That's fine for building a field, but not for testing a flow, training a team or rehearsing a migration. This guide covers what each sandbox type starts with, four ways to fill one with data, how to keep personal data out of it, and why the test data your Apex tests create doesn't help.

What each sandbox type starts with

SandboxRecords copiedData storageRefresh interval
DeveloperNone (metadata only)200 MB1 day
Developer ProNone (metadata only)1 GB1 day
Partial CopyA sample chosen by a sandbox template5 GB5 days
FullEverythingSame as production29 days

The figures are from Salesforce's sandbox licenses and storage limits. Two details catch people out:

  • Users are always copied. User records come across in every sandbox type, even when no other records do.
  • Partial Copy samples at random. It copies up to 10,000 records per object, and relationships are only kept for master-detail and required lookup fields. Ordinary lookups can point at records that didn't make the sample, and contacts or opportunities created without an account are skipped.

Four ways to fill a sandbox

ApproachHow realisticPersonal dataRepeatable
Copy production
Partial Copy or Full sandbox
Real dataAll of it, unless maskedOnly by refreshing (every 5 or 29 days)
Copy and mask
Data Mask & Seed
Real structure, masked valuesReplacedMasking runs on each new copy
Load prepared files
Salesforce CLI, Data Loader
As good as your filesNone, if you write the filesYes: the same data every time
Generate
Snowfakery, schema-aware generators
Plausible values that fit the schemaNoneYes, at any volume
The four approaches side by side. Most teams combine two: a masked copy for user acceptance testing, and loaded or generated data for development orgs.

1. Copy production

A Full sandbox is the only complete copy, and the only type Salesforce supports for performance and load testing. Partial Copy is cheaper and refreshes more often, but its sample is random within the objects you choose in the template. Both bring every customer's personal data with them, which is the main argument for the next option.

2. Copy and mask

Data Mask & Seed replaces personal data in a sandbox with realistic synthetic values. It has been available to all customers since the Summer '26 release as a core app with nothing to install, and it handles up to 350 million records per masking job. It replaces the older Data Mask managed package, whose support ended on July 9, 2026. Salesforce lists generating synthetic data into an empty sandbox as a feature still to come.

3. Load prepared files

For development orgs, a small, known dataset kept in source control is often the best option: every developer and every scratch org gets the same records. The Salesforce CLI has two families of commands:

  • sf data import tree loads JSON files that describe records and their relationships. Salesforce positions it for small sets of data, such as fewer than 3,000 records. A plan file links several files together and the CLI batches them into the API's 200-record requests. The matching sf data export tree takes a query that returns at most 2,000 records.
  • sf data import bulk and sf data upsert bulk use Bulk API 2.0 for larger volumes, one object per CSV file. Upserts take an external ID, which lets you re-run a load safely.
sf data export tree --query "SELECT Id, Name, (SELECT Id, LastName FROM Contacts) FROM Account LIMIT 50" --plan --output-dir data --target-org dev-sandbox
sf data import tree --plan data/Account-Contact-plan.json --target-org qa-sandbox

4. Generate it

Generators create records that fit your schema without copying anyone's data. Salesforce.org's open-source Snowfakery uses YAML recipes: each object template says how many rows to make, child records can be nested inside a parent, and the reference function links rows together. CumulusCI runs those recipes against an org:

cci task run snowfakery --recipe datasets/accounts_with_contacts.yml

One caution: the Snowfakery repository was archived on September 18, 2026 and is now read-only, though CumulusCI is still maintained. Schema-aware generators, including AI-based ones, take a different approach: they read each object's fields, picklist values and required fields from the org and generate records to match, so the data keeps up as the schema changes.

Keep personal data in production

Salesforce's Well-Architected guidance is direct: build development and test cycles on "synthetic data with realistic characteristics", so regulated data stays inside production. It lists Full sandboxes holding production personal data "without access controls or data masking" as an anti-pattern. In practice:

  • Mask any sandbox that receives a copy of production, before you widen access to it.
  • Use loaded or generated data in Developer and Developer Pro sandboxes and in scratch orgs.
  • Copy only the objects a test actually needs.

Why Apex test data doesn't fill a sandbox

Apex tests create their own data, but it never reaches the org. Salesforce's documentation is explicit that "Apex test data is transient and isn't committed to the database". Records created in an @TestSetup method are rolled back when the test class finishes, and even tests annotated with SeeAllData=true roll back what they create. As the Salesforce DX guide puts it, Apex tests create their own data, but UI, API and user acceptance tests "do need baseline data".

Choosing an approach

  • Building and unit testing: a small dataset loaded with sf data import tree, kept with the code.
  • User acceptance testing: a Partial Copy or Full sandbox, masked, or a generated dataset at realistic volume.
  • Performance and load testing: a Full sandbox.
  • Demos and training: generated data, so nothing real appears on a shared screen.
  • Rehearsing a migration: generated data at the volumes and parent-child shapes of the real migration, then a final rehearsal in a Full sandbox.

Fill an empty sandbox in minutes

The Salesforce Test Data Generator reads your org's schema and generates realistic, related records for any createable object, parents before children, validated before every insert.

Explore the Test Data Generator

Sources

  1. Sandbox Licenses and Storage Limits by Type · Salesforce Help
  2. Sandbox Types and Templates · Salesforce Help
  3. Sandbox Setup Considerations · Salesforce Help
  4. Which Records Are Copied When You Refresh a Salesforce Partial Data Sandbox · Salesforce Help
  5. Protect Sensitive Data with Data Mask & Seed · Salesforce Help
  6. Data Mask Managed Package Retirement · Salesforce Help
  7. Work With Small Datasets · Salesforce DX Developer Guide
  8. data import tree · Salesforce CLI Command Reference
  9. data import bulk · Salesforce CLI Command Reference
  10. Snowfakery documentation · Salesforce.org
  11. Automate Data Operations · CumulusCI documentation
  12. Understanding Test Data · Apex Developer Guide
  13. Work with Data · Salesforce DX Developer Guide
  14. Trust · Salesforce Well-Architected
  15. Operational Excellence: DevOps Patterns · Salesforce Well-Architected

Related reading

Request a demo