Sub topic 12
Preparing for a refresh: protect your work
This chapter assumes you know what a sandbox is, how the four sandbox types differ, and what a refresh does. A refresh replaces the sandbox's metadata (configuration and code) with a copy of its source org. It replaces data too, according to the sandbox type. Anything that exists only in the sandbox is lost. This chapter shows how to check for that before you start.
What a refresh overwrites
A refresh deletes the old sandbox and creates a new one from the source. The following items are at risk:
- Apex classes, triggers, flows, and fields that were never deployed to production.
- Test records and data you loaded by hand.
- Sandbox-only settings such as named credentials, custom settings values, and integration endpoints.
- Users, permission assignments, and email addresses changed in the sandbox.
Production does not hold any of these, so a refresh cannot bring them back.
A pre-refresh checklist
Work through these steps before you start a refresh.
- Find unreleased work. Ask each developer and admin what is still only in the sandbox. Compare the sandbox with your version control repository.
- Retrieve or deploy metadata. Commit it to source control, or deploy it to the next environment. Change sets and the Salesforce CLI both work for this.
- Export data you need. Use Data Export or Data Loader to save test data, such as records for a regression suite. Keep the files outside the sandbox.
- Record sandbox-only configuration. Write down integration endpoints, API credentials, and any custom setting values. Better still, script them (see the SandboxPostCopy chapter).
- Tell the team. Announce the refresh date and the time the sandbox will be unavailable. Ask people to stop work and commit their changes.
- Check dependencies. Look for connected tools, such as CI jobs or middleware, that point to the sandbox. They will need new credentials afterwards.
Retrieving metadata with the CLI
If your team uses source control, a retrieve from the sandbox shows what you might lose. This command retrieves all Apex classes into a local project. It assumes the sandbox is authorized with the alias dev1.
sf project retrieve start --metadata ApexClass --target-org dev1
git statusgit status lists classes that differ from your repository. Review each one, then commit it or decide to discard it on purpose.
The order of work
Common mistakes
- Trusting memory. People forget small changes, such as a validation rule edited in Setup. Compare with source control instead.
- Skipping data. Developer sandboxes copy no production records, so hand-made test data is lost after a refresh.
- Refreshing during active testing. A QA cycle in progress stops when the sandbox is replaced. Pick a quiet time.
- Forgetting integrations. Credentials and endpoints reset, so connected systems fail until you update them.
Exercise
A developer has built a flow and loaded 200 test accounts in a Developer sandbox. The team plans to refresh it tomorrow. Name three actions to take first.
Show answer
Retrieve the flow and commit it to source control, or deploy it to another environment. Export the 200 test accounts with Data Loader or Data Export and store the file outside the sandbox. Tell the team about the refresh time. Writing down sandbox-only settings, such as integration endpoints, is also correct.