How to Copy Production Data into a Salesforce Sandbox (Step by Step)

To copy production data into a Salesforce sandbox, decide which records you need, then either refresh a Partial Copy or Full sandbox with a template, or load the data into an existing sandbox with Data Loader or an API replication tool. Load parents before children, relate records by external IDs, mask PII, and verify the counts afterward.

Moving the rows is easy. The hard part is keeping the relationships intact and keeping production PII out of an environment with looser access. The steps below work whichever tool you use.

Step 1: Decide what data the sandbox actually needs

Start with the test you want to run, not with the whole org. A QA cycle for a new quoting flow might need Accounts, Contacts, Opportunities, Products, Price Books, and Quotes from the last two quarters. It doesn't need ten years of Tasks.

Write the scope down per object, including the filter:

  • Objects and the relationships between them (lookups, master-detail, polymorphic fields like WhoId/WhatId)
  • Filters per object (CloseDate = LAST_N_QUARTERS:2, a set of named test accounts)
  • Volume, checked against the target's storage. Developer sandboxes hold 200 MB and Developer Pro 1 GB (Salesforce sandbox types)
  • Sensitive fields that need masking or exclusion

A smaller, well-chosen dataset loads faster, fails less, and exposes less PII.

Step 2: Pick a copy method

There are three realistic approaches, and the right one depends on how much control and how often you need it.

Method Target org Record selection Relationships PII handling How often
Partial Copy / Full refresh with a sandbox template A refreshed sandbox (existing data wiped) Object-level via template; Partial Copy samples up to 10,000 parent records per object Handled by Salesforce Copied as-is unless you mask afterward Every 5 days (Partial) / 29 days (Full)
Data Loader or Salesforce CLI export/import Any existing org Any SOQL you write Your job: load order and external IDs Your job: transform the CSVs Whenever you run it
API replication tool Any existing org Per-object filters Remapped automatically Depends on the tool; some mask in transit On demand, often incremental

If a template-based refresh gives you what you need and the refresh cadence is fine, use it, since the platform does the work. The trade-offs are the refresh interval, the loss of anything built in the sandbox, and PII landing unmasked. Otherwise, load into an existing sandbox with one of the other two methods. The remaining steps assume you're doing that.

Step 3: Prepare external IDs in the target

Record IDs are org-specific, so a lookup copied from production points at a record that doesn't exist in the sandbox. The standard fix is an External ID field on each object you load, holding the source record ID. For example, add Source_Id__c, marked External ID and Unique.

With that field in place, you can:

  • Upsert instead of insert, so re-running a load updates records instead of duplicating them
  • Relate children to parents by external ID. Data Loader lets you map a lookup column to the parent's External ID field instead of a Salesforce ID (Import related records with an External ID)

One caveat from that same article: polymorphic fields such as the Activity WhatId and WhoId, and a custom object's Owner field, can't be mapped to external IDs. You'll resolve those to target IDs yourself, with a lookup table from source ID to new ID.

Step 4: Load in dependency order

Load parents before children. A typical order is:

  1. Standalone reference data (Products, Price Books, custom settings, reference objects)
  2. Accounts
  3. Contacts
  4. Opportunities, Cases, and other Account/Contact children
  5. Line items and junction objects (OpportunityLineItem, custom junctions)
  6. Activities, Files, and anything polymorphic

Two patterns break simple ordering. Self-references (Account ParentId, a hierarchy on a custom object) need two passes: insert the records with the self-lookup blank, then update it once every record has a target ID. Circular references between two objects need the same trick on one side of the loop.

Step 5: Handle record types and owners

Record types: the same record type can have a different ID in each org, so don't copy RecordTypeId values as they are. Match record types by DeveloperName and translate each source ID to the target ID before loading.

Owners: OwnerId must point to an active user in the target org. If the sandbox wasn't refreshed from production, those users may not exist. Either map owners by username or email to target users, or fall back to a single integration or admin user. If you care about who created a record and when, the "Set Audit Fields upon Record Creation" permission lets the loading user set CreatedDate, CreatedById, and the LastModified fields on insert.

Step 6: Mask PII before it lands

Mask sensitive fields before or during the load, not afterward. If you mask after loading, real data sits in the sandbox until the masking job finishes, and any automation that fires on insert (emails, outbound integrations) has already seen real values.

Use deterministic masking where you can. The same input always produces the same masked output, so a Contact's masked email still matches the same value on related records. Our guide to masking PII in sandboxes compares six ways to do this.

Step 7: Tame automation during the load

Validation rules, flows, and triggers were written for users entering data one record at a time, not for bulk historical loads. Expect them to reject valid historical records (a required field added last year) or to fire side effects such as tasks, emails, and integration callouts.

The usual approach is a bypass switch: a custom permission or hierarchy custom setting that validation rules, flows, and triggers check before running, granted only to the loading user. Keep the bypass narrow, and turn it off after the load so you're still testing real behavior. Also check the sandbox's email deliverability setting before you load anything with real-looking addresses.

Step 8: Verify the copy

Don't stop at "the job finished." Check:

  • Record counts per object against the source query
  • Orphans: children whose lookup is blank but shouldn't be
  • Error files: every failed row, grouped by error message. Most failures come from a few root causes.
  • Spot checks: open a few complex records (an Opportunity with line items, a Case with emails) and compare them with production
  • Masking: search the sandbox for a known real email domain to confirm nothing slipped through

Save the queries and the load order as a runbook. You'll repeat this, and the second run should be one command.

Where Syntharil fits

Steps 3 through 6 are exactly what Syntharil's sandbox replication automates. You pick objects and give each one a SOQL filter. It then copies into any org you own: it provisions the external ID fields, inserts in dependency order, remaps lookups including self-referential and polymorphic ones, matches record types by developer name, and masks PII deterministically in transit. It doesn't copy User records (ownership falls back to the target's running user), Chatter, or field history.

Bottom line

Copying production data into a sandbox comes down to three things: a deliberate scope, correct load order with external IDs, and PII that never lands unmasked. A template-based refresh is the simplest option when its cadence and all-or-nothing behavior work for you. For anything more targeted or more frequent, load into an existing sandbox, either with Data Loader and a disciplined runbook or with a replication tool that handles the relationship plumbing for you.

FAQ

Can I copy production data into a Developer sandbox?

Yes. Developer and Developer Pro sandboxes don't receive production data on refresh, but you can load records into them through the API, up to their storage limits (200 MB and 1 GB).

Why do my child records fail with an invalid cross-reference error?

Usually the lookup still holds the production record ID, which doesn't exist in the sandbox. Load parents first and relate children by an external ID, or remap the lookup to the parent's new sandbox ID.

Can I keep the original CreatedDate when loading records into a sandbox?

Yes, on insert only. An admin enables the 'Set Audit Fields upon Record Creation' permission in the target org, and the loading user can then set CreatedDate, CreatedById, and the LastModified fields on new records.

Do I need to mask production data in a sandbox?

If the data includes personal information, you almost certainly should. Sandboxes usually have more users and weaker controls than production, so mask or exclude PII before or during the copy.

Related reading

Try Syntharil free