Sub topic 4
Capturing a Baseline Before You Deploy
This chapter assumes you know package.xml manifests, basic Git (commit, branch, tag), and have deployed with Salesforce CLI before. Salesforce has no rollback button for a successful deployment. To undo a release, you need a record of what the org looked like before it. That record is your baseline.
Why a baseline matters
A deployment overwrites the metadata in the target org. Salesforce does not keep the previous version for you. If a release succeeds but breaks something, you must redeploy the old versions yourself. You can only do that if you saved them first.
You have two sources for a baseline:
- A retrieve backup: a copy of the components as they exist in the org right now.
- A source control baseline: the Git commit or tag that matches what is deployed.
Use both when you can. They answer different questions.
| Source | Strength | Weakness |
|---|---|---|
| Retrieve backup | Shows the real org state, including changes made directly in the org | Covers only the components in your manifest |
| Git baseline | Easy to review, diff, and revert | Can differ from the org if someone edited the org by hand |
Retrieve a backup with the same manifest
Retrieve the components you are about to change, using the same manifest you will deploy. This captures exactly the versions that will be overwritten.
sf project retrieve start --manifest manifest/package.xml --target-org prod --output-dir backup/pre-release
sf project deploy validate --manifest manifest/package.xml --target-org prod --test-level RunLocalTestsThe first command writes the current production versions to backup/pre-release. The second validates the release without committing it. Validation is covered in the next chapter, so treat it here as a safe dry run.
Check what the backup contains
Do not assume the retrieve worked. Look at the output folder and compare it to the manifest.
- Confirm the folder exists and is not empty.
- Spot-check one Apex class and one object file for content.
- Confirm every component type in
package.xmlhas a matching folder. - Record the target org, the date, and the release name.
A backup you never opened is a guess. A failed or partial retrieve can look like success if you only read the last line of output.
Pin the Git baseline
Your repository should match production before you merge the release. Tag the commit that represents the deployed state so you can find it quickly later.
git checkout main
git pull
git tag -a pre-release-2026-12-01 -m "Production baseline before release"
git push origin pre-release-2026-12-01If you later need to revert, the release merge commit is the thing to revert, and the tag tells you what you are returning to. A later chapter uses git revert -m 1 <merge-commit-sha> for this.
Detect drift
Drift is a difference between Git and the org, usually caused by someone editing the org directly. If you roll back from Git and the org had hand edits, you can lose those edits or restore a state that never existed in production.
Compare your backup to your repository. A plain diff is enough:
git diff --no-index --stat <repo-source-dir> backup/pre-releaseReplace <repo-source-dir> with the folder in your repo that holds the same components, for example force-app/main/default. The retrieve may use a different folder layout, so check the paths before you trust the output. If the diff shows differences you did not expect, decide which version is correct before you deploy.
How the pieces fit
Store the backup where the team can find it
A backup on one laptop is not much use at 2 a.m. Put it somewhere shared and name it so it matches the release. Many teams commit it to a separate branch or attach it to the release ticket. Whatever you choose, write the location into the release notes.
What a backup does not cover
Metadata backups hold configuration and code. They do not hold records, and they do not restore data changes made by a release. Treat the backup as the answer for metadata only. Data changes are covered in a later chapter.
Exercise
You are about to deploy a release that changes 10 Apex classes and adds one new class. You retrieve a backup using the release manifest. The backup contains only 10 classes. Is something wrong?
Show answer
No. The new class does not exist in production yet, so there is nothing to retrieve for it. The backup correctly holds the 10 existing versions. To undo the new class after a bad release, you would delete it with a destructive changes manifest.
Exercise
Your Git main branch matches the release plan, but a colleague edited a validation rule directly in production last week. Why might a rollback from Git alone be risky, and what step in this chapter catches the problem?
Show answer
Redeploying from Git would overwrite production with a version that lacks the colleague's edit. The drift check, which compares the retrieve backup to the repository, shows the difference before you deploy so you can decide which version is correct.