Sub topic 14
What changes after a refresh
A refresh replaces a sandbox with a new copy of its source org, so many things differ afterwards. Some changes are deliberate safety measures. Others are side effects of copying production configuration into a different environment. This chapter assumes you know what a refresh does and how to prepare for one. It covers what to expect and what to check once the sandbox is back.
Everything you built in the sandbox is gone
The sandbox is rebuilt from the source org, so anything that exists only in the sandbox is lost. That includes unsaved metadata changes, test records, and configuration experiments. The sandbox ends up matching the source org as of the moment the copy started.
What you get back depends on the sandbox type:
| Sandbox type | Metadata after refresh | Data after refresh |
|---|---|---|
| Developer, Developer Pro | Full copy of production | None. You must load test data. |
| Partial Copy | Full copy of production | A sample, optionally limited by a sandbox template |
| Full | Full copy of production | All data, or a subset if a template limits it |
Records that are copied keep the same record IDs as in the source org. Code or data files that reference production IDs therefore still work in Partial Copy and Full sandboxes. That is not true for records you create in the sandbox afterwards.
Usernames and email addresses change
Salesforce deliberately changes user identities so that sandbox users cannot be mistaken for production users, and so that the sandbox cannot send email to real people.
- Usernames get the sandbox name appended. If the sandbox is named
dev1, the production user[email protected]becomes[email protected]. - Email addresses are rewritten with
.invalidadded, for example[email protected]. Salesforce cannot deliver to these addresses, so notifications to real users do not go out by accident.
The rewrite also applies to email fields on users who are not part of your team. If you want a tester to receive email, edit their user record and set a valid address. Salesforce then sends a confirmation message to that address.
Users sign in to a sandbox at https://test.salesforce.com, or through the sandbox's My Domain URL, which has the form https://mycompany--dev1.sandbox.my.salesforce.com. Bookmarks and saved login URLs for the old environment may need updating.
Email deliverability is restricted
After a refresh, the Access to Send Email setting (Setup, Email, Deliverability) is System email only. Only system-generated messages, such as password resets, are sent. Email from Apex, workflows, flows, and users is suppressed.
The three levels are:
- No access: no outbound email of any kind.
- System email only: only system messages are sent.
- All email: all outbound email is sent. Use this only with test data.
Raise this setting only when you are testing email behaviour, and only after confirming that no real customer addresses exist in the sandbox. A Full sandbox contains real customer email addresses, and a Partial Copy sandbox can too. Setting the level to All email in either one can send test messages to real customers.
Integration settings still point to production
Metadata is copied without regard to which environment it belongs to. Any setting that holds an external URL, credential, or endpoint arrives pointing at the production target. Check these places:
- Named credentials and external credentials
- Remote site settings and CORS entries
- Outbound message endpoints
- Custom settings and custom metadata that hold endpoint URLs or API keys
- Connected apps, whose callback URLs and OAuth policies may refer to production
- Single sign-on and authentication provider settings
- Email-to-Case, Email Services, and other inbound addresses, which are generated per org
A sandbox that still calls a production payment gateway or ERP can create real transactions. Switch each integration to its test endpoint before you let any automation run.
You can list the endpoints that Apex callouts use with a query. Run it in Anonymous Apex or the Developer Console:
List<NamedCredential> credentials = [
SELECT DeveloperName, Endpoint
FROM NamedCredential
ORDER BY DeveloperName
];
for (NamedCredential nc : credentials) {
System.debug(nc.DeveloperName + ' -> ' + nc.Endpoint);
}If any endpoint is a production URL, change it before you test.
Scheduled and background work needs review
Scheduled Apex, scheduled flows, batch jobs, and scheduled report subscriptions can arrive from production. If they run unchanged, they may process sandbox data or call production systems. Open Setup, Scheduled Jobs and the flow and report schedule pages. Delete or reschedule anything that should not run in a test environment.
Local tools lose their connection
Your Salesforce CLI authorization, IDE connections, and API clients were bound to the old copy. After a refresh they may fail with an invalid session or authentication error. Authorize the org again, and use the sandbox login URL:
sf org login web --instance-url https://test.salesforce.com --alias dev1
sf data query --query "SELECT Id, Username FROM User LIMIT 3" --target-org dev1The second command confirms that the new authorization works.
A post-refresh checklist
Run the same checks after every refresh. They are good candidates for automation, which the next chapter covers with SandboxPostCopy.
You can confirm the first two checks in code:
Organization org = [SELECT Id, IsSandbox FROM Organization LIMIT 1];
System.debug('IsSandbox = ' + org.IsSandbox);
List<User> sample = [
SELECT Username, Email
FROM User
WHERE IsActive = true
ORDER BY Username
LIMIT 5
];
for (User u : sample) {
System.debug(u.Username + ' | ' + u.Email);
}You should see IsSandbox = true, usernames ending in the sandbox name, and email addresses ending in .invalid.
Common mistakes
- Assuming the sandbox still has your test data. Developer sandboxes come back empty, and the others come back with whatever production holds at that moment.
- Logging in with the production username. The sandbox username has the sandbox name appended.
- Testing a flow that sends email and seeing nothing. This is the default System email only setting, not a bug.
- Leaving an integration on a production endpoint. Review every credential and endpoint before you run tests.
- Reusing an old CLI alias without re-authorizing. The alias exists locally, but the saved session no longer matches the new org.
Exercise
A tester logs in to a freshly refreshed Developer sandbox and reports three problems: (1) their production username does not work, (2) the account list is empty, and (3) a flow that emails customers sends nothing. Explain the cause of each problem and the fix.
Show answer
(1) Salesforce appends the sandbox name to every username, so [email protected] becomes [email protected]. Log in with the new username at the sandbox login URL. (2) A Developer sandbox copies metadata only, so it has no records after a refresh. Load test data, for example with the Data Import Wizard or the CLI. (3) The refresh sets email deliverability to System email only, which suppresses flow email. This is the intended safety behaviour. Raise the setting only if you are testing email and the sandbox holds no real customer addresses.
Exercise
Your Full sandbox has just been refreshed. Name three configuration areas you should review before running any integration tests, and say why each one matters.
Show answer
Any three of the following. Named credentials and remote site settings, because they arrive pointing at production endpoints and could trigger real transactions. Connected apps and single sign-on settings, because their callback URLs and trust relationships may refer to production. Scheduled jobs, flows, and report subscriptions, because they may run against sandbox data or call external systems. Custom settings and custom metadata holding URLs or API keys, because they are copied unchanged from production.