Sub topic 11
What a refresh does and when to use it
This chapter assumes you know what the four sandbox types are, how they differ in storage, and that each type has a minimum refresh interval. It also assumes you can tell metadata (configuration and code) from data (records).
What a refresh does
A refresh replaces a sandbox with a new copy of its source org. The source is usually production, but it can be another sandbox if you created the sandbox by cloning. Salesforce does not merge changes. It rebuilds the sandbox from the source as it exists when the refresh starts.
- Metadata: All metadata is copied from the source, so your sandbox matches the source's current configuration and code.
- Data: The amount copied depends on the type. Developer and Developer Pro sandboxes copy no records. Partial Copy copies a sample, and Full copies everything. A sandbox template can narrow what Partial Copy and Full sandboxes copy.
- Sandbox-only work: Anything you built only in the sandbox is gone after the refresh. That includes unsaved Apex, flows, and test records.
The sandbox keeps its name and its type. It also keeps its place in your org's list of sandboxes, so you do not use up another sandbox license.
When to refresh
Refresh when the sandbox no longer reflects the source org in a way that matters to your work. Common reasons:
- Drift. Production has received changes that your sandbox lacks, such as hotfixes, new fields, or other teams' releases. Testing against old metadata can hide conflicts.
- Stale data. A Partial Copy or Full sandbox holds old records, and your testing needs realistic, current ones.
- A clean start. A project has finished and you want to remove leftover test data and half-built configuration.
- A broken sandbox. Metadata conflicts or corrupt test data make the sandbox hard to work in.
- Preparing for a release. QA or staging sandboxes should match production before you validate a deployment.
When not to refresh
A refresh is destructive, so avoid it in these cases:
- The sandbox holds work that has not been deployed or saved to version control.
- The minimum refresh interval has not elapsed. Salesforce blocks the refresh until it has.
- Another team is mid-test in that sandbox.
- You only need a few records or one component. Copying those across is cheaper than rebuilding everything.
Refresh and the refresh interval
Each sandbox type has a minimum time between refreshes. The clock runs from when the sandbox was last created or refreshed. Because the interval limits how often you can reset a sandbox, plan refreshes instead of using them as a quick undo.
| Situation | Better choice than refreshing |
|---|---|
| You need one changed component from production | Retrieve it and deploy it to the sandbox |
| You want to discard recent changes | Revert in version control and redeploy |
| You need a separate environment right now | Create a new sandbox, if you have a license available |
Exercise
A QA team has a Full sandbox that is three weeks behind production. Testers need current metadata, but a developer has an Apex class in that sandbox that was never saved elsewhere. Should you refresh right away? Explain.
Show answer
No. A refresh replaces everything in the sandbox, so the unsaved Apex class would be lost. First retrieve the class and commit it to version control, or deploy it to another org. Then refresh, provided the minimum refresh interval for a Full sandbox has passed.