Sub topic 2
Capturing a Baseline Before You Deploy
This chapter assumes you understand Salesforce metadata, package.xml, basic Git, and Salesforce CLI (sf). A rollback restores metadata. It does not automatically restore records or other data.
Capture a baseline
Before changing production, retrieve the metadata that currently exists there. Store it outside your working directory so it becomes a known recovery point.
sf project retrieve start --manifest manifest/package.xml \
--target-org prod \
--output-dir backup/pre-releaseCommit the retrieved files or archive them with the release record. Also record the deployment manifest, Git commit, test level, and the person who approved the release. A baseline is useful only if you can identify exactly which version it represents.
Validate first and use quick deploy
A validation checks whether Salesforce can deploy the package without changing production. Run the same tests that the real deployment requires.
sf project deploy validate \
--manifest manifest/package.xml \
--target-org prod \
--test-level RunLocalTestsSave the validation job ID. If validation succeeds, deploy that exact validated package with quick deploy:
sf project deploy quick \
--job-id 0AfXXXXXXXXXXXXXXX \
--target-org prodQuick deploy reduces repeated testing and helps ensure that the deployed components match the validated package. A successful validation does not prove that the release is safe for users. It only proves that the metadata and required tests passed.
Cancel a deployment that is still running
If a deployment is still processing and you decide to stop it, first inspect its status:
sf project deploy report \
--job-id 0AfXXXXXXXXXXXXXXX \
--target-org prodCancel the job if it remains in progress:
sf project deploy cancel \
--job-id 0AfXXXXXXXXXXXXXXX \
--target-org prodConfirm the final status after requesting cancellation. Do not assume that a cancellation request has completed.
Roll back by redeploying the previous version
For a successful but harmful deployment, restore the prior source-controlled version and deploy it as a new release:
git revert -m 1 <merge-commit-sha>
sf project deploy start \
--manifest manifest/package.xml \
--target-org prod \
--test-level RunLocalTestsThis restores metadata represented by the previous version. It does not undo record edits, deleted data, emails, external-system changes, or every setting changed outside the manifest.
Exercise
Why should you retrieve production metadata before deploying?
Show answer
It creates a known baseline that can be redeployed if the release succeeds but causes problems.