How to seed data into an org
Scratch orgs start empty. To give one the reference and sample records a project needs, you seed
data into it. The toolchain offers two built-in ways, both driven by sfdx-project.json; for
anything genuinely complex, reach for a dedicated data tool instead.
Seeding runs automatically on scratch creation
org scratch-create imports the configured data after it deploys metadata (skip it with
--skip-data-import). You can also run either importer on its own against any org with
npm run data:import -- --target-org <org> or npm run data:import:csv -- --target-org <org>.
Way 1 — tree/plan import (related records)
Use this for a small set of records with relationships (an Account with its Contacts and Cases,
say). It uses sf data import tree, which preserves the reference graph.
-
Export a graph from an org that already has the data:
This writes the record JSON plus a
*-plan.jsonthat ties the files together. -
Commit those files under a data directory (for example
datasets/json/). -
Register the plan pattern in
sfdx-project.jsonunderplugins.diadx.dataImports.planFiles— patterns may use a directory wildcard, and only files ending in-plan.jsonare imported:
npm run data:import (and scratch creation) then imports each plan.
Way 2 — CSV bulk upsert (single-object volume)
Use this for a larger set of records for one object, keyed by an external id so re-runs update
rather than duplicate. It uses sf data upsert bulk.
- Put the CSV under
datasets/csv/. -
Register it in
sfdx-project.jsonunderplugins.diadx.dataImports.csvFiles, naming the object, the file, and the external-id field:
npm run data:import:csv (and scratch creation) upserts each file with
sf data upsert bulk --sobject <object> --external-id <field>.
When to reach for a dedicated data tool
The built-in importers do not handle circular or self-referential relationships, deep hierarchies, large multi-object graphs, record anonymisation, or precise upsert ordering across many objects. For those, run a purpose-built tool as its own step — the toolchain does not wrap them:
- SFDMU
- CumulusCI datasets, with Snowfakery for synthetic data
Seed data is committed in clear text
Anything under datasets/ is tracked in the repository. Never commit real customer data or PII —
seed with synthetic records only.