Sub topic 2
Salesforce DX source format: what the files look like
This chapter assumes you know basic Git (branches, commits, merge), can open a Salesforce DX project, and can read simple XML. It describes the files you will see when a merge conflict happens, so you can tell which ones are safe to edit by hand.
Source format in one view
Salesforce DX stores metadata as many small files under force-app/main/default. This is called source format. The older metadata format packs related items into a few large files. Source format splits them so that two developers are less likely to edit the same file.
Each metadata type has its own folder. Most files are XML, and their names end in -meta.xml.
force-app/main/default/
├── classes/
│ ├── AccountService.cls
│ └── AccountService.cls-meta.xml
├── objects/
│ └── Account/
│ ├── Account.object-meta.xml
│ └── fields/
│ └── Region__c.field-meta.xml
├── permissionsets/
│ └── Sales_Access.permissionset-meta.xml
├── labels/
│ └── CustomLabels.labels-meta.xml
├── layouts/
│ └── Account-Account Layout.layout-meta.xml
└── flows/
└── Update_Account.flow-meta.xmlTwo kinds of files
Source format has two broad groups. Knowing which group a file belongs to tells you how risky a conflict is.
| Kind | Examples | What a conflict looks like |
|---|---|---|
| Code with a companion file | Apex classes, triggers, Lightning web component JavaScript | The `.cls` or `.js` file conflicts like any source code. The `-meta.xml` companion rarely does. |
| Single XML file for a component | Permission sets, profiles, layouts, flows, custom labels | The whole component is one XML file, so unrelated edits can land in the same file. |
Objects are a special case. A custom object is decomposed into a folder. Each field, validation rule, and record type gets its own file. Two people adding different fields touch different files, and Git merges them without any conflict.
Permission sets, profiles, and custom labels are not decomposed in the same way. Every field permission is a child element inside one file. That is why the example in this tutorial conflicts, and it is the main reason this topic exists.
What the XML looks like
A permission set is a root element with repeated child elements. Each child is one setting.
<?xml version="1.0" encoding="UTF-8"?>
<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
<fieldPermissions>
<editable>true</editable>
<field>Account.Region__c</field>
<readable>true</readable>
</fieldPermissions>
<label>Sales Access</label>
</PermissionSet>Three details matter during a merge.
- Child elements are sorted. The CLI writes them in a stable order, usually alphabetical by element name and then by key. Two branches that add different entries often insert them at the same position, which Git sees as a conflict.
- Indentation is four spaces. A hand edit with tabs or two-space indents creates noisy diffs later.
- Each block is self-contained. A
fieldPermissionselement opens and closes on its own, so you can usually keep, drop, or reorder whole blocks without breaking the file.
Check what you are looking at
Before you edit a conflicted file, confirm which type it is and whether it is generated.
# List the metadata files changed on your branch
git diff --name-only main...HEAD -- force-app
# Count the fieldPermissions blocks in a permission set
grep -c "<fieldPermissions>" force-app/main/default/permissionsets/Sales_Access.permissionset-meta.xmlThe second command gives a quick count. After a merge, the count should equal the number of entries from both sides, minus any you chose to drop on purpose.
Exercise
Two developers each add a new custom field, Tier__c and Segment__c, to the Account object. Each also adds a field permission for it to the same permission set. Which change is likely to cause a Git conflict, and why?
Show answer
The permission set change. Each field is its own file under objects/Account/fields/, so those files are separate and merge cleanly. Both field permissions are child elements in one Sales_Access.permissionset-meta.xml file, and both are inserted at the same position, so Git reports a conflict.