Sub topic 14
Rolling back and shipping hotfixes
This chapter assumes you know how a work item moves through a DevOps Center pipeline, how pull requests merge into stage branches, and basic Git commands such as revert and log. It covers what to do when a release goes wrong.
Why DevOps Center has no rollback button
DevOps Center promotes work items forward. It does not have an "undo release" action. A deployment to production changes the org's metadata, and Salesforce does not keep a snapshot you can restore. Your recovery tool is Git. The branch history records every change, so you can create a new change that reverses an old one and send it through the pipeline like any other work item.
Choosing a recovery path
| Situation | Approach | Speed |
|---|---|---|
| The bug is small and the fix is obvious | Hotfix: a new work item with the correction | Fast |
| The fix is unclear or risky | Revert: a new work item that undoes the faulty change | Medium |
| The deployment failed partway | Fix the cause and promote again. A failed deployment does not change the org. | Fast |
Salesforce deployments are atomic by default. If a deployment fails, nothing is saved in the target org. A failed promotion needs a new attempt, not a rollback.
Rolling back with a revert work item
Do not delete commits from the shared branches. Rewriting history breaks the branches that other work items depend on. Create a revert instead.
- Find the merge commit that introduced the problem.
- Create a new work item named for the rollback, such as "Revert WI-142".
- Undo the change on that work item's branch.
- Open a pull request, get it reviewed, and promote it through each stage.
To find the commit, compare the stage branches:
git fetch origin
git log --oneline origin/main..origin/UATThen create the revert on the work item branch:
git checkout -b revert-wi-142 origin/main
git revert -m 1 <merge-commit-sha>
git push origin revert-wi-142The -m 1 option tells Git which parent of the merge commit to keep. Parent 1 is the branch the merge landed on.
Shipping a hotfix
A hotfix is an urgent production fix. In DevOps Center, a hotfix still uses a work item, and it still goes through a pull request. The aim is to shorten the path, not skip it.
The last step matters most. If the fix reaches only production, the next normal release can overwrite it, or the stage branches will conflict. After the hotfix ships, make sure the same change exists in every earlier stage.
Checking a fix before promotion
Run a validation-only deployment against production, or a sandbox that mirrors it, before you promote:
sf org login web --alias uat
sf project deploy start --source-dir force-app --target-org uat --dry-run --test-level RunLocalTestsA dry run deploys nothing. It confirms the change compiles and the tests pass.
Common errors
- Reverting an individual commit when the change arrived as a merge. Use
-m 1with the merge commit. - Skipping the back-merge. The bug returns in the next release.
- Hand-fixing production directly. The org then drifts from Git.
Exercise
A release reached production and broke a validation rule. Why should you create a revert work item and not delete the merge commit from the main branch?
Show answer
Deleting the commit rewrites shared history, which breaks other branches and work items built on it. A revert work item adds a new commit that undoes the change, keeps the history intact, and goes through review and promotion like any other change.
Exercise
After a hotfix is promoted to production, which extra step prevents the fix from being lost?
Show answer
Merge the same change back into the earlier stage branches, such as UAT and development, so that later releases include it and do not conflict with it.