Here is some content on Salesforce trunk-based development:
| Pitfall | Why it happens | Solution | | :--- | :--- | :--- | | | Developers are afraid to merge incomplete code. | Use Feature Toggles . Merge incomplete code hidden behind a custom setting or static resource switch, so it doesn't activate in production until ready. | | Broken Trunk | Merging bad code breaks the build for everyone. | Enforce strict CI. If the trunk breaks, fixing it becomes the team's #1 priority. Stop all other merges until main is green. | | Sandbox Sprawl | Teams using Dev Sandboxes forget to refresh them. | Use Scratch Orgs defined in project-scratch-def.json to ensure every branch starts with a fresh, clean state. | | Flaky Tests | Apex tests fail randomly, blocking merges. | Isolate and disable flaky tests immediately. They destroy confidence in the Trunk. Fix them in isolation. |
Flows are massive XML files. Merging two versions of a Flow is often impossible via Git. salesforce trunk-based development
Instead of building a massive feature for 2 weeks, developers break work into small chunks.
Developers do not branch off other developers' branches. They branch off main . Here is some content on Salesforce trunk-based development:
force-app/main/default/profiles/ .xml -diff -merge force-app/main/default/objects/ /*.xml -diff -merge
| Strategy | When to Use on Salesforce | |----------|----------------------------| | (commit directly to main ) | Small teams (<5 devs), high trust, simple metadata (no profiles). | | Short-lived branches + PRs | Most Salesforce teams. 24-hour max lifetime. | | Release branches (only as needed) | Regulated industries. Create release/v1.2 from main , patch separately. | | | Broken Trunk | Merging bad code
| Mechanism | Use Case | Example | |-----------|----------|---------| | (Hierarchy) | Per-user, per-org rollout | FeatureToggle__c.enableNewDashboard__c | | Custom Metadata Type | Bulk configuration | Feature_Flag__mdt queried in Apex | | Permission Set | Visibility gates | New Lightning page assigned only to test users | | Apex if statements | Code-level toggle | if(FeatureService.isEnabled('NEW_FLOW')) |
Salesforce development has historically been "org-centric," where developers make changes directly in a sandbox and metadata is the source of truth. However, the modern Salesforce paradigm is "source-driven development," where code and configuration in a Version Control System (VCS) are the source of truth.
By moving away from long-lived feature branches that often lead to "merge hell," Salesforce teams can achieve faster release cycles and higher environment stability. 1. Why Trunk-Based Development for Salesforce?