Sub topic 8
Resolving conflicts in profiles and permission sets
This chapter assumes you can run git merge, read conflict markers, and use the sf CLI against a sandbox. You should also know that source-format metadata is XML under force-app.
Why these files conflict most
A profile or permission set is one XML file that lists many grants. A profile can hold fieldPermissions, objectPermissions, classAccesses, tabVisibilities, layoutAssignments, and userPermissions. The CLI writes these elements sorted, so two developers who each add a grant near the same alphabetical spot edit adjacent lines. Git cannot tell that the changes are independent and reports a conflict.
Profiles are the worst case, because they are large and nearly every feature touches them. Permission sets are smaller and more focused, which makes their conflicts easier to resolve.
Additive conflicts: keep both
When each side adds a different element, keep both blocks and delete the three marker lines. Keep the alphabetical order, so the next merge stays clean. The earlier example, where one branch added Account.Tier__c and the other added Account.Segment__c, resolves this way.
Competing edits: choose deliberately
Sometimes both sides change the same element. Here one branch removed edit access from Account.Tier__c and the other kept it:
<<<<<<< HEAD
<fieldPermissions>
<editable>false</editable>
<field>Account.Tier__c</field>
<readable>true</readable>
</fieldPermissions>
=======
<fieldPermissions>
<editable>true</editable>
<field>Account.Tier__c</field>
<readable>true</readable>
</fieldPermissions>
>>>>>>> feature/tier-editDo not keep both blocks. Two fieldPermissions entries for the same field are a duplicate, and a deployment can reject them. Pick one block, or write a merged one. Ask the authors which access level is intended. For security grants, the narrower choice is the safer default until someone confirms.
Check these rules while you edit:
editableset totruerequiresreadableset totrue.- Each field, object, class, or tab appears once per file.
- A grant to something that no longer exists, such as a deleted field, fails at deploy time.
Common errors
- Leaving one marker line behind. The file is no longer valid XML.
- Keeping both versions of the same element. The XML is well-formed but the deployment fails or behaves unpredictably.
- Accepting a whole side with
--oursor--theirs. This silently discards the other branch's grants. Use it only when you know the other side's changes are irrelevant. - Breaking the sort order. The file still deploys, but the next retrieve rewrites it and creates noisy diffs.
Verify before committing
Run the checks in order, from cheapest to most expensive:
grep -rnE '^(<<<<<<<|=======|>>>>>>>)' force-app
xmllint --noout force-app/main/default/permissionsets/Sales_Access.permissionset-meta.xml
sf project deploy start --dry-run --source-dir force-app --target-org my-sandbox
git add force-app/main/default/permissionsets/Sales_Access.permissionset-meta.xml
git commitThe grep finds leftover markers and xmllint confirms the file parses. The dry run asks the org to validate the deployment without saving it. It catches references to missing fields and duplicate entries that the first two checks cannot see.
Exercise
After a merge, a permission set has two fieldPermissions blocks for Account.Tier__c. One sets editable to false and the other sets it to true. The file passes xmllint. Why is it still wrong, and what should you do?
Show answer
The file is well-formed, but it lists the same field twice, which a deployment can reject. Remove the duplicate and keep one block with the access level the authors intended. Then run the dry run against a sandbox to confirm.