Sub topic 9
Validating the Resolution with a Deployment Dry Run
This chapter assumes you can resolve a conflict by hand, run git commands, and use the Salesforce CLI (sf) against a sandbox or scratch org. Here you check that a resolved merge is valid before you commit it.
Why a clean-looking file is not enough
Removing the <<<<<<<, ======= and >>>>>>> lines does not prove the merge is correct. The XML can still be broken, or it can be well-formed but reference something that does not exist in the target org. Git cannot see either problem, because it only merges text.
A deployment dry run asks the org to validate the metadata without saving it. The org parses the XML, checks references such as fields and Apex classes, and reports errors. Nothing changes in the org.
Three layers of checking
Run the checks from cheapest to most expensive. Each layer catches a different kind of mistake.
| Check | Catches | Needs an org |
|---|---|---|
| `grep` for markers | Leftover conflict lines | No |
| `xmllint --noout` | Unclosed tags, bad nesting | No |
| `--dry-run` deploy | Missing fields, invalid values, test failures | Yes |
# 1. Check that no conflict markers remain
grep -rnE '^(<<<<<<<|=======|>>>>>>>)' force-app
# 2. Check that a resolved file is still well-formed XML
xmllint --noout force-app/main/default/permissionsets/Sales_Access.permissionset-meta.xml
# 3. Validate against the target org without saving changes
sf project deploy start --dry-run --source-dir force-app --target-org my-sandbox
# Finish the merge
git add force-app/main/default/permissionsets/Sales_Access.permissionset-meta.xml
git commitThe grep command prints nothing when the project is clean. In this example, xmllint also prints nothing when the file parses. Any output means you should fix the file before you continue.
Reading dry-run output
If the dry run fails, the CLI lists each problem with a file name and a line. A typical failure after a bad merge is a fieldPermissions entry that points to a field that is not in the org. That happens when the field's own metadata file was lost or was never merged.
Read these errors by type:
- A parse error means the XML is broken. Go back to the file and look for a missing closing tag.
- A "no such field" or "no such object" error means a reference points to something absent. Check that the metadata for that component exists in your merged project.
- A test failure means the merged code changes behavior. Fix the cause, not the test.
Choosing the target org
Use a sandbox or scratch org whose metadata is close to the branch you are merging into. A dry run against an org that lacks the new fields from either branch gives misleading errors. If your merge includes Apex, add --test-level RunLocalTests so the dry run also runs tests.
sf project deploy start --dry-run --source-dir force-app --target-org my-sandbox --test-level RunLocalTestsWhen the dry run keeps failing
If you cannot tell which side caused the error, narrow the scope. Deploy only the resolved file with --source-dir pointing at that file. If the error disappears, the problem is in another file. If you are still stuck, git merge --abort returns you to the state before the merge, and you can start again.
Exercise
You resolved a conflict in a permission set, and xmllint --noout printed nothing. Why should you still run a dry run before committing?
Show answer
xmllint only proves the file is well-formed XML. It cannot tell whether the references inside it are valid. The dry run asks the org to check them, so it catches problems such as a fieldPermissions entry for a field that does not exist, and it can run tests.