Sub topic 1
Why automate Salesforce deployments
Prerequisites
This chapter assumes you know the following:
- Basic Git and GitHub usage: branches, pull requests, and merging.
- Salesforce metadata and Apex tests.
- Basic command-line use and YAML syntax.
You don't need to write any pipeline code yet. This chapter explains the problem the rest of the tutorial solves.
The problem with manual deployments
Many teams still move changes between orgs with change sets. A developer picks components in a sandbox, uploads them to another org, and a second person deploys them. This works for a small team. It breaks down as the team and the number of changes grow.
Common failures include:
- Missing components. Someone forgets a custom field or a permission set, and the deployment fails or behaves differently in production.
- No history. A change set records little about who changed what and why. Git records every change.
- No review. Nothing forces a second person to read the change before it ships.
- Late test failures. Apex tests often run only at production deployment, so a failure appears when the pressure is highest.
- Org drift. Sandboxes and production slowly stop matching, because changes are applied by hand in different orders.
What CI/CD changes
Continuous integration (CI) means every change is built and tested automatically when it is proposed. Continuous delivery (CD) means a tested change can be deployed through a repeatable process. In this tutorial, Git becomes the source of truth. Orgs receive what is in Git instead of whatever someone selected in a change set.
The pipeline you will build follows this flow:
What you will build
The tools are a Salesforce DX project, the Salesforce CLI (sf), and GitHub Actions. The finished pipeline does the following:
- Validates each pull request with a check-only deployment that runs Apex tests, without changing the org.
- Deploys automatically when a change merges.
- Requires an approval before production.
- Deploys faster by sending only changed metadata, and avoids overlapping deployments.
Later chapters cover authentication, secrets, delta deployments, quick deploys, scratch orgs, and troubleshooting.
When automation is worth it
Automation has a cost. Someone must build and maintain the pipeline, and a slow or flaky test suite will slow every pull request.
| Situation | Recommendation |
|---|---|
| One admin, few changes, declarative only | Change sets may be enough |
| Several developers working in parallel | Automate |
| Apex or Lightning code in production | Automate |
| Audit or compliance requirements | Automate |
A good rule is to automate once more than one person changes the same org, or once a failed production deployment would be costly.
Exercise
Name two problems with change sets that a Git-based pipeline solves, and say how.
Show answer
Examples: (1) Missing components. A project in Git holds all the metadata, so the pipeline deploys what is committed, not a hand-picked list. (2) No review. Pull requests require a reviewer before merge, and the pipeline validates the change with Apex tests first. History and drift are also acceptable answers, since Git records every change and every org receives the same source.