Sub topic 2
Decomposition: How a Custom Object Is Split into Many Files
Assume you know basic Salesforce metadata, XML, directories, command-line use, and Git. This chapter focuses on how source format decomposes metadata for easier maintenance.
One object, two layouts
In Metadata API format, a custom object is usually one Account.object file. Its fields and object settings are stored together.
Source format is the Salesforce DX layout. It splits the object into an object folder. The object settings use one file, while each custom field gets its own file:
force-app/main/default/
└── objects/
└── Account/
├── Account.object-meta.xml
└── fields/
└── Rating_Notes__c.field-meta.xmlThis decomposition makes Git changes smaller. A change to one field does not create a large diff containing unrelated object settings.
Companion `-meta.xml` files
A companion metadata file describes configuration for a source file. The suffix is part of the filename, not an optional label.
For example, an Apex class has both files:
classes/
├── MyClass.cls
└── MyClass.cls-meta.xmlThe .cls file contains Apex. The -meta.xml file contains metadata such as the API version and whether the class is available to tests.
Source-format custom fields also use metadata filenames, such as Rating_Notes__c.field-meta.xml. Static resources, Lightning Web Components, and other metadata types use their own companion-file conventions. Do not rename or omit these files when moving source-format content.
`sfdx-project.json` and package directories
The sfdx-project.json file identifies a Salesforce DX project and its package directories:
{
"packageDirectories": [
{ "path": "force-app", "default": true }
],
"namespace": "",
"sourceApiVersion": "60.0"
}The path points to a directory containing source, commonly force-app/main/default.
Converting between formats
Use the Salesforce CLI to convert layouts:
sf project convert source --root-dir force-app --output-dir mdapi_output
sf project convert mdapi --root-dir mdapi_output --output-dir force-app
sf project deploy start --metadata-dir mdapi_output --wait 10The first command creates Metadata API files. The second recreates source-format decomposition. Verify the output by checking expected object, field, and companion files before deploying.
Exercise
Where should a new custom field appear in source format?
Show answer
As its own .field-meta.xml file inside the custom object's fields directory.