Sub topic 2
A Trunk-Based Flow with `main` as the Source of Truth
Assume you know basic Git commands, Salesforce metadata such as Apex classes and flows, sandbox concepts, and command-line use. In Salesforce, metadata is the configuration and code stored in files. Git should be the source of truth. Orgs are places where that metadata is tested or released.
Keep `main` authoritative
A trunk-based workflow keeps one shared main branch. Developers create short-lived branches from the latest main, validate their changes, and merge them through pull requests. After review, main represents the next releasable version.
This model avoids long-lived branches that diverge from the team’s current metadata. It works best when changes are small and merged often.
Branch names and lifetimes
Use names that identify the work and its purpose:
feature/case-routing-rulesfix/opportunity-triggerchore/update-api-version
Start every branch from an up-to-date main. Keep it alive for hours or a few days, not weeks. A small branch is easier to review, deploy, and merge.
Build a feature and open a pull request
git switch main
git pull --ff-only origin main
git switch -c feature/case-routing-rules
sf org create scratch --definition-file config/project-scratch-def.json --alias case-routing
sf project deploy start --source-dir force-app --target-org case-routing
# Build and test, then retrieve approved declarative changes
sf project retrieve start --target-org case-routing
git add force-app
git commit -m "Add case routing rules"
git push -u origin feature/case-routing-rulesOpen a pull request from the feature branch into main. The request should explain the behavior, tests, and deployment impact.
Resolve metadata merge conflicts
A conflict occurs when two branches change overlapping metadata. Read both versions, preserve the intended behavior, and test the resolved files. XML metadata can conflict even when developers changed different settings because one file may contain many settings.
Reduce conflicts by keeping branches short, assigning ownership for high-conflict metadata, and making focused commits. Do not blindly choose “ours” or “theirs.”
Validate without saving
A pull request check can run a check-only deployment:
- name: Validate Salesforce metadata
run: sf project deploy start --source-dir force-app --dry-run --test-level RunLocalTests --target-org ci-org --wait 60The --dry-run option validates deployment and tests without saving changes to the target org. Store authentication values in the CI system’s secrets, not in the repository.
Exercise
Why should a feature branch start from the latest main?
Show answer
It reduces divergence and exposes conflicts before the pull request is reviewed.