Sub topic 13
Running a refresh step by step
This chapter walks through a sandbox refresh from the first click in Setup to the point where users can log in again. It assumes you know the four sandbox types, their refresh intervals, and how to prepare for a refresh, which earlier chapters cover. Here the focus is on the refresh wizard, what happens while Salesforce builds the copy, and how activation works.
What happens during a refresh
A refresh does not modify your existing sandbox in place. Salesforce builds a new copy of the source org in the background. Your current sandbox stays available until you activate the new copy. At activation, the old sandbox is deleted and replaced.
This has two practical consequences:
- You can keep working in the old sandbox, or export changes from it, while the copy is being built.
- Anything you do in the old sandbox after the refresh request is lost at activation.
Before you open the wizard
Check these conditions first. If any fails, the Refresh option is unavailable or the result will not be what you want.
- The refresh interval has elapsed. Each type has a minimum wait since the last creation or refresh. If the interval has not passed, Salesforce disables the Refresh link.
- No copy is already in progress. A sandbox cannot be refreshed while a copy of it is running or waiting for activation.
- Your pre-refresh work is saved. Unsaved metadata, such as changes not yet committed to source control or deployed to production, must be retrieved before you activate. Data in the sandbox is overwritten.
- You have the permission. You need the Manage Sandboxes permission, which system administrators normally have.
- You know which template and Apex class you want, if the sandbox is Partial Copy or Full.
Step 1: Open the Sandboxes page
- From Setup, enter
Sandboxesin Quick Find and select Sandboxes under Environments. - Find the sandbox in the list. The table shows its name, type, status, location, and the date of its last refresh or creation.
- Confirm the status is Active. A sandbox in another state, such as Processing, cannot be refreshed.
You must run the refresh from the org the sandbox was created from. For a sandbox cloned from another sandbox, that is the source sandbox, not production.
Step 2: Start the refresh
Click Refresh in the row for the sandbox you want. Salesforce opens the same wizard used for creation, with the existing name filled in. The name is fixed. If you need a different name, you must create a new sandbox instead.
Step 3: Choose the sandbox type
The wizard lets you change the sandbox type during a refresh, provided your org has an unused license of the target type. For example, a Developer sandbox that has outgrown its storage can be refreshed as a Developer Pro or Partial Copy sandbox.
Keep these points in mind:
- The new type governs the refresh interval going forward, not the old one.
- Changing from a larger type to a smaller one can fail if the source org's data or metadata exceeds the smaller storage limit.
- A license is released back to your pool once the old sandbox is replaced, not when you click Refresh.
Step 4: Choose what data to copy
The data options depend on the type.
| Type | What the wizard asks | Notes |
|---|---|---|
| Developer | Nothing about data | Metadata only. Records are not copied. |
| Developer Pro | Nothing about data | Metadata only, with more storage than Developer. |
| Partial Copy | A sandbox template (required) | The template controls which objects and how many records are copied. |
| Full | Template (optional) and a choice to include field tracking history, Chatter data, or both | More options mean a longer copy. Full sandboxes copy all records unless a template narrows them. |
Choosing a template is the best way to shorten a Partial Copy or Full refresh. A template that selects only the objects your testing needs often finishes much sooner than an unrestricted copy.
Step 5: Choose an Apex class to run after the copy
The wizard has a field labeled Apex Class. Pick a class that implements SandboxPostCopy to run automatically once the copy completes. Typical uses are masking email addresses, resetting integration endpoints, and creating test users. The class runs in the new sandbox, not the old one, so it only affects the data after activation.
If the field is empty because no eligible class exists in the source org, you must create and deploy the class to the source org before starting the refresh. A class added to the old sandbox is not visible to the wizard when you run it from production. Writing the class itself is covered in a later chapter.
Step 6: Choose how to activate
Newer wizards offer an Auto Activate option. The two modes behave differently:
- Manual activation (default behavior): the new sandbox is created and waits. Salesforce emails you. You click Activate on the Sandboxes page when you are ready. The old sandbox keeps working until that moment.
- Auto Activate: Salesforce activates the new copy as soon as it is built, which immediately deletes the old one.
Use auto activation only if the sandbox has no unsaved work and no one will be mid-task when the swap happens. For shared QA or UAT sandboxes, manual activation lets you pick a quiet time and announce it.
Step 7: Submit and wait
Click Create at the end of the wizard. The sandbox status changes to Pending or Processing, and the copy joins a queue.
Duration varies with type and data volume:
- Developer and Developer Pro copies usually finish in minutes to a few hours, since only metadata is copied.
- Partial Copy copies take longer because of the data sample.
- Full copies can take many hours and sometimes more than a day for large orgs. Queue time is part of that wait.
You cannot cancel a refresh once it starts copying, but you can delete the sandbox, which loses everything. Do not use deletion as a way to stop a refresh.
Step 8: Activate and verify
When the copy finishes, Salesforce sends an email to the user who requested it. Then:
- Return to the Sandboxes page. The status shows Completed.
- Click Activate (if you did not choose auto activation) and confirm the warning.
- Wait for the status to return to Active.
- Log in at
https://test.salesforce.comusing the sandbox username, which is the production username with.sandboxnameappended, for example[email protected].
After you log in, run through your post-refresh checklist. Confirm that email deliverability is set to System email only, that the Apex class you chose has run, and that integration endpoints are not pointing at production. The next chapter covers these changes in detail.
Common errors and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| Refresh link is missing or disabled | Interval not elapsed, or a copy is in progress | Wait, or check the status column. |
| Apex class does not appear in the wizard | Class is not deployed to the source org, or does not implement `SandboxPostCopy` | Deploy to the source org, then restart the wizard. |
| Template not offered | The sandbox is Developer or Developer Pro, or no template exists | Create a template in the source org first. |
| Type change rejected | No free license for the target type | Free a license or keep the current type. |
| Copy fails with a size error | Source data exceeds the target type's limit | Use a template to reduce the data, or pick a larger type. |
| Cannot log in after activation | Wrong username or login URL | Append `.sandboxname` to the username and use the test login URL. |
Exercise
Your team's Developer Pro sandbox is mid-sprint, and you start a refresh on Monday. On Tuesday a developer adds a new Apex class to that sandbox. The refresh finishes Wednesday and is set to Auto Activate. What happens to the Tuesday class, and what should you have chosen instead?
Show answer
The class is lost. The refresh copies the source org as it was when the copy ran, so the Tuesday change never reaches the new sandbox. With Auto Activate, the new copy replaces the old sandbox as soon as it is ready, which deletes the class. You should have chosen manual activation, retrieved the class from the old sandbox (or committed it to source control) after it was built, and only then clicked Activate.