Sub topic 3
Protecting Main and Reviewing Salesforce Changes
Assume you know basic Git, Salesforce metadata, sandboxes, and command-line use. This chapter connects review rules with release and recovery practices.
Protecting main and reviewing changes
Treat main as the source of truth for deployable metadata. Protect it with repository rules:
- Require pull requests for every change.
- Require at least one reviewer who understands Salesforce metadata.
- Require automated validation to pass.
- Prevent force pushes and direct commits.
- Require a clean, up-to-date branch before merging.
Review the deployment contents, not only the Apex diff. Check profiles, permission sets, flows, objects, and destructive changes for unexpected effects.
Promoting releases and tagging them
After a pull request merges, deploy the exact main commit to a UAT sandbox. Run functional and integration tests there. Promote the same commit to production after approval. Do not rebuild the change manually in each org.
Tag the commit that reached production so the deployed state can be identified later.
| Stage | Source | Main check |
|---|---|---|
| UAT | Merged `main` commit | User and integration testing |
| Production | Approved UAT commit | Deployment validation and monitoring |
git switch main
git pull --ff-only origin main
git tag -a v2026.12.1 -m "Release 2026.12.1"
git push origin v2026.12.1Shipping a hotfix safely
Create a short-lived hotfix branch from the current production commit or main, depending on your release process. Make the smallest safe change, validate it, and merge it through the same review rules. Deploy the fix, then merge or rebase the fix into every branch that must contain it. This prevents the next release from reverting the hotfix.
Detecting and reconciling org drift
Org drift is a difference between source control and an org caused by a direct change, an emergency deployment, or incomplete retrieval. Schedule metadata comparisons or run them before releases. Retrieve approved changes into a branch, review them, and merge them into main. For unapproved changes, revert the org or capture the decision in source control.
Deploying only what changed
A delta deployment contains only changed metadata. It reduces deployment time and lowers risk, but it must include dependencies and destructive changes deliberately. Generate the delta from known Git commits, then validate it against a representative org.
Splitting projects into modules
Large teams can split related metadata into modules or unlocked packages. Packages create clearer ownership and version boundaries. They also require dependency management, package versioning, and a plan for shared metadata. Keep tightly coupled components together until the boundary is useful.
Exercise
Why should a hotfix be merged back into the normal development line?
Show answer
Otherwise a later release can overwrite the production fix.