To keep regulated data out of a Salesforce sandbox, classify the fields that fall under your rules, decide for each one whether it is masked, replaced with synthetic values or left out, write a refresh rule that runs the same steps each refresh, and limit who can open the copy. Each step leaves a record you can check.
Why a sandbox copy becomes a regulated data problem
A sandbox is a copy of an org used for development, testing or training. Depending on its type, it can also carry records from the source as they stood when the copy was made. Regulated records in production, such as health details, payment card values or government identifiers, travel with any copy that includes data unless someone removes or replaces them first. Teams often treat sandboxes as low risk, but developers work from laptops, partners receive logins and testers export records to spreadsheets.
The working rule is simple: regulated data enters a non-production org when a named owner has approved it and the protections are written down. Decide what the copy may contain before the refresh runs, not after someone spots a problem.
Classify the data before anything is copied
Start with an inventory of fields, not a general label such as customer data. For each object, list the fields that hold regulated values and the reports, flows and integrations that read them. A text field called Notes can hold a national identifier someone typed in, so sample real records and look for the patterns your rules describe.
Record each field in a short register with four columns: object, field, classification and treatment. Treatment is what happens in the copy: keep, mask, synthesize or exclude. Keep the register beside the sandbox runbook so whoever runs a refresh can read it without asking.
Choose masking, synthetic data or exclusion for each field
Masking keeps the field and its format but replaces the real value, so a test that expects a certain format still gets one. Synthetic data generates new values that look realistic and match no real person. Exclusion leaves the field blank or drops the record. Pick the least risky option that still lets the test run. A billing test may need a realistic amount but not a real card number.
Masking should be consistent. If one customer name appears on three related records, the masked version must match on all three, or joins and roll-ups in the test will break. Keep the mapping key outside the sandbox and confirm with the data owner that sandbox users cannot reverse it.
Synthetic sets need coverage, not just volume. Include blank values, very long text and records with no parent, because a set of tidy records lets a test pass in the sandbox and then fail on real data.
Some fields have no test use. Free-text notes, attachments and history tables often fall into this group. Exclude them when no test depends on them, and write the exclusion in the register so nobody assumes the field was masked.
Write a refresh rule that runs the same way each time
A refresh rule is the written sequence that turns the register into action. It names the owner, the trigger, the steps in order and the sign-off required before users get access. A rule kept in one person’s head fails the first time that person is away.
Timing and scope of a refresh are covered in sandbox refresh planning. This section covers the data rules that apply to each run.
A workable sequence: confirm the source org and records you expect, run the masking or synthesis job before any user logs in, run the checks described below, record the refresh date, job version and owner sign-off, then open access.
Masking after users log in leaves a window where regulated values are visible, so hold access until the sign-off is recorded.
Define what happens when a masking job fails partway. The rule should say whether the partial copy is deleted, re-run or left closed, and who decides. A half-masked copy is easy to overlook.
For help planning this work, see Salesforce implementation.
Control who can reach the sandbox
Access should follow the same logic as production. Map each role to the objects and fields it needs, starting with the roles people actually hold. A developer may need to edit metadata and load test data without viewing restricted fields. A tester may need to run a process against synthetic records and nothing more.
Building permission sets for a small team is covered in permission set design for small teams.
Check field-level security and object access in the sandbox, not just in production. Profiles and permission sets in the copy decide what a tester sees. Masking and access are separate controls, so each needs its own test.
Limit sign-in to named people. Review the active user list after each refresh and disable any login the register does not explain. Connected apps and integration users need the same check, since an integration whose endpoint still points at production can write to live records from a test.
Test the masking and access controls
After the refresh, review the result as someone other than the person who ran the job. Sample records from each object in the register and look for real values in masked fields, notes, descriptions and linked files. A text search for the patterns your classification uses can catch values a field-level check misses.
Test as a user holding each standard role in the access map, open the records that role should see, and confirm the restricted fields are hidden or masked as designed. A check run as an administrator says little about a tester’s view, because administrator access is wider.
Masking can change values that validation rules, flows and other automation depend on. A masked postal code that fails a format check can stop a record from saving. When a masked value trips a validation rule, changing that rule without breaking the integrations behind it is covered in validation rules without breaking integrations.
Load test records with the same tools your team uses for production work, and choose the loader on purpose. A load that silently leaves out restricted fields can hide a gap in the test data, so compare loaded counts and field values against the register after each load. The loader differences are covered in choosing Salesforce data loader options for migration.
Report each refresh and act on exceptions
Give each refresh a short report for the data owner: source org and date, job version, counts of fields masked, synthesized and excluded per object, the access list at sign-off, and the exceptions. An exception that stays open across two refreshes means the rule needs changing, not another manual fix.
A line saying the refresh completed gives an approver nothing to check. A count of records masked and a list of open exceptions gives them something to decide.
Troubleshooting a sandbox that holds regulated data
If review finds regulated values in a sandbox, first remove logins for the affected users so access stops. Then record what was found, where, when the copy was made and who could have seen it. Decide whether to re-mask, refresh again or delete the copy. Do not export data to investigate, because each export creates a copy you must also control.
Find the cause before the next refresh. Common causes are a field missing from the register, a job that finished with warnings, a file attached to a record that the job did not touch, and an integration that wrote real values after masking. Each has a different fix: a register change, a stop condition in the rule, or a change to the integration’s endpoint or credentials.
Whether an incident needs reporting under the rules for your data is a decision for the data owner and your compliance contact, not for the administrator running the refresh.
Questions about regulated data in sandbox copies
Is restricting access enough to use real regulated records in a sandbox?
Restricting access limits who sees the values but leaves them in the copy. The copy then has its own exports and integrations to control. Keeping real values out is the simpler position to defend, since it does not rely on each later step being done right.
Why does field-level security not protect regulated values on its own?
Field-level security decides which users can read or edit a field. It does not change the stored value, so any user granted access through another profile or permission set still reads the real value. Use masking to change what is stored and access rules to control who can read it.
How often should the refresh rule be reviewed?
Review it when the register changes, when a new integration writes to a restricted object, and after any exception that the rule could not handle. Also review it when your team starts using a different kind of sandbox, since the data a copy receives may differ.
Who should sign off before users get access to a refreshed sandbox?
The data owner for the restricted fields should approve the treatment, and the administrator should approve the access list. Two named approvals on the record keep the sign-off from resting on one person’s judgment, which matters when the person who ran the job is also the one checking it.
Can synthetic data support tests of reports and dashboards?
It can, if the set includes the value ranges, groupings and edge cases the reports depend on. Compare totals from a few known records in the copy against the source to confirm the report logic holds before relying on the figures.