Sub topic 2
Keeping Salesforce Metadata XML Valid While You Edit
Assume you know basic Git merge commands, Salesforce DX source format, and XML nesting. A merge conflict is resolved only when Git has no unresolved markers and Salesforce can parse the resulting metadata.
Remove conflict markers without breaking XML
Git places three marker lines around competing text:
<<<<<<< HEAD
<fieldPermissions>...</fieldPermissions>
=======
<fieldPermissions>...</fieldPermissions>
>>>>>>> feature/new-fieldThese markers are not XML. Remove <<<<<<<, =======, and >>>>>>>, then choose or rewrite the content between them. Keep every element properly nested and every opening tag paired with a closing tag.
A useful model is:
Keep both sides when changes are additive
Changes are additive when both branches introduce independent metadata. For example, one branch adds Account.Tier__c and another adds Account.Segment__c. Keep both complete fieldPermissions blocks.
Do not merge only the inner lines. Each block must remain a complete child of PermissionSet:
<fieldPermissions>
<editable>false</editable>
<field>Account.Tier__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>true</editable>
<field>Account.Segment__c</field>
<readable>true</readable>
</fieldPermissions>Check that repeated elements are allowed by that metadata type and that each field appears only as intended.
Choose between competing edits
Competing edits describe the same metadata item. If both branches change the same permission, label value, or setting, keeping both may create duplicate or contradictory entries. Determine which business decision is current, then retain one value or combine the changes deliberately.
For a generated or easily re-retrieved file, taking one side can be safer than hand-editing:
git checkout --theirs -- path/to/fileUse this only when you have confirmed what “theirs” contains.
Resolve profiles and permission sets
Profiles and permission sets often contain many repeated permission blocks. Match entries by their identifying child, such as field, object, or name, rather than by position. Preserve the surrounding metadata and remove every marker. Then run:
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-sandboxExercise
Two branches add permissions for different fields in one permission set. Should you keep one block or both?
Show answer
Keep both complete blocks, remove the conflict markers, and validate the XML and deployment.