Sub topic 1
Why Salesforce Changes the Branching Question
Prerequisites
Assume you know basic Git operations, pull requests, Salesforce metadata such as Apex classes and flows, and the roles of sandboxes, scratch orgs, and production orgs.
Why Salesforce Changes the Branching Question
In a typical application, Git stores source code that runs after compilation or packaging. Salesforce development is different because much of the application is metadata: XML descriptions of objects, permissions, flows, Apex, and configuration. A deployment applies that metadata to an org, where Salesforce runs it.
This creates two sources of truth:
- Git contains the intended state.
- An org contains the deployed state, which people may change directly.
A branching strategy must therefore coordinate both Git branches and Salesforce orgs. A branch is not itself an environment. It is a line of source changes that must be deployed to an org for testing.
Laying Out a Salesforce DX Project in Git
A Salesforce DX project gives the repository a predictable structure. The sfdx-project.json file identifies the metadata directories and the Salesforce API version.
{
"packageDirectories": [
{ "path": "force-app", "default": true }
],
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "62.0"
}Keep metadata in force-app/main/default, grouped by type. Store configuration files, deployment scripts, and tests in the same repository when they are part of delivery. Review metadata changes as carefully as application code because a small XML edit can change permissions, automation, or data behavior.
Mapping Orgs to the Places Code Lives
Use org types for different purposes:
- A scratch org is short-lived and usually represents one feature branch.
- A developer sandbox is longer-lived and suits shared development or integration.
- A UAT sandbox validates a release candidate.
- Production is the deployed system, not a development workspace.
The mapping should remain simple: branch changes are tested in a disposable or assigned development org, then promoted through controlled environments.
Comparing Branching Models for Salesforce
| Model | Strength | Risk |
|---|---|---|
| GitFlow | Separate release and hotfix paths | Long-lived branches and metadata drift |
| Trunk-based | Short branches and frequent integration | Requires strong automated validation |
| Environment-per-branch | Clear org ownership | Expensive to maintain and easy to confuse with source |
For most Salesforce teams, trunk-based development with short-lived feature branches is the practical default. It keeps main releasable and limits conflicts. GitFlow can help teams with scheduled releases, while environment-per-branch models make sense only when org provisioning and synchronization are reliable.
Exercise
Why should a feature branch not be treated as a permanent Salesforce environment?
Show answer
A branch stores source changes, while an org stores deployed metadata and data. Permanent pairing increases drift and maintenance cost.