Sub topic 3
Validating a Resolved Salesforce Metadata Merge
Assume you know Git branches and merges, Salesforce DX source format, XML structure, and the sf CLI. A resolved file is not ready to commit just because Git reports no unmerged paths. Salesforce must also accept the metadata.
Validate with a deployment dry run
First check the working tree and unresolved files:
git status
git diff --name-only --diff-filter=UInspect the affected files for conflict markers. Then run a deployment dry run against a sandbox or scratch org:
sf project deploy start \
--dry-run \
--source-dir force-app \
--target-org my-sandboxA dry run validates the deployment without saving changes to the org. Fix XML errors, missing dependencies, and Salesforce metadata validation errors before staging the file.
Special cases and re-retrieval
Flows, layouts, and bundle metadata often contain generated or ordered content. A small functional change can produce a large diff. For a competing change, compare both versions with the intended configuration in the org. If the file is difficult to merge safely, re-retrieve the authoritative metadata:
sf project retrieve start \
--metadata "Layout:Account-Account Layout" \
--target-org my-sandboxReview the retrieved file, compare it with the branch changes, and reapply only the required local edits. Do not re-retrieve blindly, because retrieval can overwrite local work.
Merge tools and conflict prevention
A three-way merge tool can show the common ancestor, current branch, and incoming branch together. Git can remember a repeated resolution:
git config rerere.enabled trueUse .gitattributes to select merge behavior for files that should use a consistent strategy. A merge driver should be added only when the team understands its behavior. Automatically choosing one side can silently discard permissions or configuration.
Reduce future conflicts by keeping changes small, assigning ownership for shared metadata, and avoiding unrelated formatting changes. Prefer source format and consistent ordering. Deploy and validate branches before merging them.
Git conflicts and source-tracking conflicts
A Git merge conflict occurs when two commits modify overlapping lines. A source-tracking conflict occurs when local project files and changes in a scratch org or source-tracked org disagree. The commands and remedies differ, so identify which comparison produced the conflict before choosing a resolution.
Validate merges automatically in CI
CI should run the same checks on every merge request: detect conflict markers, validate the project, and perform a deployment dry run against a disposable or validation org. This catches malformed XML and Salesforce-specific errors before the merge reaches the main branch.
Exercise
Why should a resolved metadata file pass a Salesforce deployment dry run before it is committed?
Show answer
The dry run checks Salesforce metadata rules and dependencies without changing the target org, so errors can be fixed before the merge is shared.