Sub topic 14
Rolling back and shipping hotfixes
This chapter assumes you can promote a work item through a pipeline, read a pull request, and use basic Git commands such as revert and log. It also assumes you have used sf project deploy start. It covers what to do when a release goes wrong and how to ship an urgent fix without breaking the pipeline.
There is no undo button
DevOps Center does not roll back a deployment. Promotion merges a work item's changes into a stage branch and deploys that branch's metadata to the stage's org. Nothing in that sequence stores a "previous state" you can restore with one click.
Recovery is therefore a forward move. You produce a new change that returns the org to a known good state, and you send it through the pipeline like any other change. Git history is what makes this possible, because every promoted change is a commit you can identify and reverse.
Three facts shape every recovery plan:
- Reverting a commit changes files in the repository. It does not change an org until a deployment carries that change there.
- Deploying source adds and updates components. It does not remove components that disappeared from the repository, unless the deployment includes a deletion.
- Data is never rolled back. Records created, changed or deleted by users or automation stay as they are.
Choosing a response
Decide quickly which of the three responses fits the incident.
| Situation | Response | Typical speed |
|---|---|---|
| A small defect with an obvious fix | Roll forward with a normal work item | Hours |
| A change that must be withdrawn | Revert, then promote the revert | Hours |
| Production is broken and the pipeline is too slow | Hotfix path with documented exceptions | Minutes to hours |
Roll forward is the default. A revert is the right choice when you cannot fix the defect quickly or when other work depends on the removal.
Rolling back by reverting
The revert is a Git operation on the commit that introduced the change. First find the commit on the production branch.
git fetch origin
git log --oneline --merges -n 10 origin/mainIf the pull request was merged with a merge commit, revert it with -m 1, which keeps the first parent (the branch you merged into). If it was squash-merged, there is one ordinary commit, so leave out -m 1.
git checkout -b revert-wi-0042 origin/main
git revert -m 1 3f9c2ab
git push origin revert-wi-0042You can then deliver the revert in two ways.
- Redo it as a work item. Create a work item titled for the revert, make the opposite change in the development environment, and commit it through DevOps Center. This keeps the audit trail inside the tool and is the safest route for most teams.
- Review the Git revert as a pull request. Open a pull request from the revert branch and merge it according to your repository rules. Check that your pipeline's stage branches and work item records still agree afterward. If they do not, the next promotion may re-introduce the change.
Either way, the revert must pass through every stage in order. The faulty commit also sits in the earlier stage branches (Dev, UAT). If you revert only on the production branch, the next promotion from UAT will bring the faulty change back.
Deletions need extra care
Suppose the bad release added a custom field and an Apex class. Reverting the commit removes both files from the repository. Deploying that state does not delete either component from production, because a source deployment only writes what it contains.
For these cases, deploy the deletion explicitly. Check first which of your metadata types DevOps Center handles for deletions, since coverage varies by type. For anything it does not handle, use the CLI with a destructive manifest.
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>OrderSyncService</members>
<name>ApexClass</name>
</types>
<version>62.0</version>
</Package>Save this as destructiveChangesPost.xml. Create an empty manifest package.xml that holds only a version element, then run the deployment.
sf project deploy start \
--manifest manifest/package.xml \
--post-destructive-changes manifest/destructiveChangesPost.xml \
--target-org prodSalesforce blocks deletion of a component that other components still reference, such as a field used in a report or a flow. Remove those references first, and expect to repeat this step for each blocker.
Shipping a hotfix
A hotfix is a fix for a production problem that cannot wait for the normal release train. The usual difficulty is that work items travel through the stages in order, and the earlier stages may hold unreleased changes that you do not want to ship.
Consider the state of the pipeline before you choose an approach.
- UAT is clean. Nothing unreleased sits in the stages ahead of production. Run a normal work item quickly, with a short review and focused tests. This is the easiest case.
- UAT holds unreleased work. A normal promotion would carry that work along. Keep the hotfix small and separate. Hold back the other work items, or finish promoting them first if they are ready.
- A stage is unusable. If a stage org is broken or frozen, some teams keep a separate, shorter pipeline for production fixes. Treat this as a designed path with its own approvers, not as an improvised bypass.
Check what a promotion would carry before you start. This command lists commits on UAT that are not yet on the production branch.
git fetch origin
git log --oneline origin/main..origin/UATIf the list contains anything other than your hotfix, stop and decide what to do with those commits.
Keep the safeguards that matter
A hotfix reduces ceremony, but it should not remove the checks that catch regressions. Make these choices in advance:
- Keep at least one reviewer on the pull request.
- Run a validation-only deployment with local tests against production before you promote.
- Name the person who can approve an exception, and record why it was used.
sf project deploy start --source-dir force-app --target-org prod --dry-run --test-level RunLocalTestsBring the fix back
After the hotfix reaches production, confirm that every earlier stage branch contains it. If it reached production by a shortcut path, the Dev and UAT branches may lack the fix. The next regular release would then overwrite it with the older version. Compare branches and merge the fix back.
git fetch origin
git log --oneline origin/UAT..origin/mainAny commit listed here exists in production but not in UAT, so it needs to be merged back.
Common mistakes
- Reverting only on the production branch. The faulty change returns on the next promotion.
- Assuming a revert deletes components. Production still holds the field or class until a deletion is deployed.
- Skipping tests under pressure. An untested hotfix that fails in production costs more than the minutes saved.
- Forgetting the back-merge. The hotfix disappears at the next release.
- Reverting a change that later work depends on. Check for later commits that touch the same files before you revert, or the revert will conflict.
Exercise
A release added a custom field and a validation rule, and users report that they cannot save records. You revert the pull request's merge commit on the production branch and deploy it. The validation rule is still active in production. Why, and what do you do next?
Show answer
A source deployment writes components that exist in the repository but does not delete components that were removed from it. The revert removed the rule's file, so nothing told production to delete it. Deploy a destructive change that names the validation rule (for example with --post-destructive-changes) or deactivate it in the org as an immediate mitigation. Also make sure the revert reaches the Dev and UAT stage branches so the next promotion does not bring the rule back.
Exercise
UAT contains two unreleased work items, and a hotfix is needed in production. Name two safe options and one risk common to both.
Show answer
Option one is to finish or hold back the unreleased work so UAT is clean, then promote the hotfix normally. Option two is to use a separate, shorter pipeline reserved for production fixes, with its own approvers. The shared risk is that the fix may not reach the earlier stage branches, so the next regular release overwrites it. You avoid this by merging the fix back into every earlier stage branch.