Sub topic 16
Troubleshooting common import failures
This chapter assumes you can export and import tree data with sf data export tree and sf data import tree, and that you know what a plan file and a reference ID are. It also assumes you have deployed your project metadata to the target org. The goal is to read a failed import, find the cause, and fix it.
How a tree import fails
sf data import tree sends records in batches, following the order in the plan file. If one record in a batch fails, the CLI reports the error and does not load that batch. Records that were already created in earlier steps stay in the org. Fix the cause, then clean up or use an upsert before you retry, or you will create duplicates.
Common failures and fixes
| Symptom in the error | Likely cause | Fix |
|---|---|---|
| `No such column` or `Invalid field` | Metadata is missing in the target org | Run `sf project deploy start` before the import |
| `REQUIRED_FIELD_MISSING` | The exported query left out a required field | Add the field to the query and export again, or edit the JSON |
| `FIELD_CUSTOM_VALIDATION_EXCEPTION` | A validation rule rejects the record | Change the data, or bypass the rule for seeding (see below) |
| `INVALID_CROSS_REFERENCE_KEY` | A reference points to a record that was not created | Check the plan order and the `saveRefs` and `resolveRefs` flags |
| `DUPLICATE_VALUE` | A unique field or duplicate rule matched an existing record | Use an upsert with an external ID, or load into a clean org |
| `STORAGE_LIMIT_EXCEEDED` | The scratch org is out of data storage | Reduce the dataset size |
Unresolved references
References are the most frequent plan-file mistake. Check these four things:
- The parent file is listed before the child file in the plan.
- The parent step has
"saveRefs": true, and the child step has"resolveRefs": true. - Every
@AccountRef1in the child file matches areferenceIdin the parent file exactly. Matching is case-sensitive. - The parent record was actually created. If the Account failed, every Contact that points to it fails too.
Fix the first error in the output first. Later errors are often side effects of it.
Validation rules, triggers, and flows
Your own automation can block seed data. A validation rule may require a field the export did not include. A trigger or flow may also create extra records or throw an error.
You have two options. Make the data satisfy the rules, which is the safer choice. Or use a custom permission or a setting that your rules check, so that the seeding user skips them. Do not deactivate rules in a shared sandbox just to load data.
Checking what was loaded
After a failed run, count what exists before you retry:
sf data query \
--query "SELECT COUNT() FROM Account WHERE Industry = 'Technology'" \
--target-org my-scratchIf partial data exists, delete it, or switch to sf data upsert bulk with an external ID so a rerun updates rows instead of duplicating them.
Reading more detail
Add --json to get the full error payload in a script. For bulk jobs, the CLI prints a job ID. Use sf data upsert resume --job-id <id> or check the job in Setup under Bulk Data Load Jobs to see per-row failures.
Exercise
Your Contact import fails with INVALIDCROSSREFERENCE_KEY. The Account step succeeded. Name two things in the plan or data files you should check.
Show answer
Check that the Account step has "saveRefs": true and the Contact step has "resolveRefs": true. Also check that each AccountId value such as @AccountRef1 exactly matches a referenceId in the Accounts file, including case. Confirming that Accounts appears before Contacts in the plan is also valid.