Sub topic 14
What changes after a refresh
This chapter assumes you know what a refresh does and how to run one. Here you will see what is different in the sandbox once it finishes.
The sandbox becomes a new copy
A refresh replaces the sandbox's metadata with a fresh copy from its source org. It also replaces the data, to the extent the sandbox type copies data. Anything you built only in the sandbox is gone unless you saved it elsewhere. The source org is usually production, though a sandbox can also be the source.
The copy is not identical to the source. Salesforce changes some settings so the sandbox cannot affect real users or live systems.
| Area | What happens after a refresh | What you do |
|---|---|---|
| Usernames | The sandbox name is appended, so `[email protected]` becomes `[email protected]`. | Log in at `test.salesforce.com` with the new username. |
| User email addresses | `.invalid` is appended, so `[email protected]` becomes `[email protected]`. | Correct the address for users who need email in the sandbox. |
| Email deliverability | Set to **System email only**. | Raise it in Setup only when you need to test outbound email. |
| Integration settings | Endpoints, named credentials, remote site settings, and SSO settings are copied from the source and may still point to production systems. | Repoint them to test systems. |
| Data | Replaced by what the sandbox type copies. | Reload test data if needed. |
Why usernames and emails change
Usernames must be unique across all Salesforce orgs. The suffix keeps a sandbox user from clashing with the production user of the same name. The .invalid suffix on email addresses stops notifications from going to real people while you test workflows and Apex. Together with the email deliverability setting, this protects your customers and colleagues from test messages.
Integrations still point at production
Many integration settings are copied unchanged from the source org. A sandbox can therefore keep calling a production endpoint, or accept requests meant for production. Check each of these after a refresh:
- Named credentials and external credentials.
- Remote site settings and CORS entries.
- Connected apps and OAuth settings.
- Single sign-on and identity provider settings.
- Custom settings or custom metadata that hold URLs, keys, or tokens.
Because this list is the same every time, it is a good candidate for automation with a SandboxPostCopy class, covered in the next chapter.
Detecting the environment in code
Code that behaves differently in a sandbox can check the IsSandbox field on the Organization object.
Organization org = [SELECT Id, IsSandbox FROM Organization LIMIT 1];
if (org.IsSandbox) {
System.debug('Running in a sandbox');
} else {
System.debug('Running in production');
}Use this check to skip calls to production-only services. Do not use it to hide bugs that appear only in production.
A post-refresh checklist
- Log in with the suffixed username.
- Fix email addresses for the users who need them.
- Confirm the email deliverability setting.
- Update integration endpoints and credentials.
- Restore any metadata or data you saved before the refresh.
- Run a smoke test of the key processes.
Exercise
After a refresh, a tester cannot log in with [email protected], and a workflow email to her never arrives. Give the cause of each problem.
Show answer
The sandbox name was appended to her username, so she must log in as [email protected] (or the matching sandbox name). Her email address now ends in .invalid, and email deliverability is set to System email only. She needs a corrected address on her user record, and deliverability must be raised if the sandbox should send email to her.