Sub topic 9
Regression testing before the upgrade
This chapter assumes you can work in Setup, know what a sandbox is, have seen Apex tests and Flows, and can run basic command-line commands. A regression test checks that something that worked before the upgrade still works after it. You run these tests in a preview environment, so you find problems before production is upgraded.
What to test and why
Release changes rarely break an org at random. They break things that depend on behavior Salesforce has changed, retired or enforced. Your impact assessment (the previous step) gives you a list of suspects. Regression testing confirms or clears each one.
Test three layers, in this order:
- Apex: unit tests, triggers, and callouts.
- Declarative automation: Flows, validation rules, and approval processes.
- Key user journeys: the handful of end-to-end tasks your business cannot lose, such as converting a lead or closing an opportunity.
Start with Apex because it is the cheapest to automate. Move to Flows and journeys, which usually need manual or UI-driven checks.
Step 1: Get a baseline
Before you blame the release for a failure, you need to know whether the test passed before. Run your Apex tests in a sandbox that is still on the current release, and save the results. Then run the same tests in the preview sandbox and compare.
Use this command to run all local tests in a preview sandbox. It waits up to 20 minutes for results.
sf apex run test \
--target-org my-preview-sandbox \
--test-level RunLocalTests \
--result-format human \
--wait 20RunLocalTests runs every test in your org except tests that come from installed managed packages. That matches what a production deployment requires, so it is the right level for a baseline.
A failure that appears only in the preview sandbox points at the release. A failure that appears in both is an existing problem. Fix it separately, or it will hide real regressions.
Step 2: Test in a preview scratch org
A preview scratch org is a short-lived org created on the upcoming release. It is useful when you want a clean environment, or when you do not have a preview sandbox. Set the release option in the scratch org definition file.
{
"orgName": "Release Preview Org",
"edition": "Developer",
"release": "Preview"
}Then create the org from that file.
sf org create scratch \
--definition-file config/project-scratch-def.json \
--alias preview-org \
--duration-days 7 \
--set-defaultA scratch org starts empty, so you must deploy your source and any test data first. It will not contain your production data or configuration, so it cannot replace a full regression pass in a sandbox.
Step 3: Test Flows and user journeys
Apex tests do not cover Flows that have no test coverage. For each Flow named in your impact assessment, run it with realistic records and check the outcome. Open Flow debug runs, and look at the fault paths as well as the happy path.
For user journeys, write short scripts that a tester can follow. A good script names the user profile, the starting record, the steps, and the expected result.
| Part of script | Example |
|---|---|
| Profile | Sales Rep |
| Start | An open Opportunity in Negotiation stage |
| Steps | Add a product, update the close date, move to Closed Won |
| Expected | Order is created, owner gets an email, no error banner |
Test with real profiles and permission sets, not only as a System Administrator. Many regressions show up only for users with narrower access.
Common errors
- Testing only as an administrator, which hides permission-related failures.
- Skipping the baseline, so existing failures are mistaken for release regressions.
- Using a sandbox with too little data, so Flows and triggers never run their real paths.
- Ignoring integrations. Test callouts and inbound API calls against the preview sandbox, with the external systems pointed at it.
Exercise
Your Apex tests fail in the preview sandbox. What should you do first to decide whether the release caused the failures, and why?
Show answer
Run the same tests in a sandbox that is still on the current release and compare. If the tests also fail there, the problem already existed and is not caused by the release. If they fail only in the preview sandbox, treat them as regressions and triage them against the release notes and Release Updates.
Exercise
Why is a preview scratch org not enough on its own for regression testing?
Show answer
A scratch org starts without your production data and configuration, so Flows, triggers and integrations may not run their real paths. Use it for clean, fast checks, and use a preview sandbox with representative data for the full regression pass.