Sub topic 12
Choosing the right format for your workflow
This chapter helps you decide which on-disk layout to use for a given job. It assumes you know what a package.xml manifest is. It also assumes you can read an sfdx-project.json file and have run sf project convert at least once. It does not repeat how decomposition works. It focuses on decision criteria, trade-offs, and the mistakes teams make when they pick a layout by habit.
The short answer
Use source format as the working layout of your repository. Use Metadata API format only at the edges, where a tool or process requires it.
Source format is the layout that Salesforce DX projects use. Its files are small, so version control shows small diffs. The Salesforce CLI deploys and retrieves it directly. Metadata API format is the monolithic layout described by a package.xml. It remains the right choice for a few specific cases, listed below.
What each format optimizes for
The two layouts exist for different reasons. Knowing the reason tells you when each one fits.
| Concern | Metadata API format | Source format |
|---|---|---|
| Custom object | One `Account.object` file | A folder with `Account.object-meta.xml` plus one file per field |
| Entry point | `package.xml` at the root | `sfdx-project.json` at the root |
| Diff size in Git | Large, one file changes for any field edit | Small, one field is one file |
| Merge conflicts | Frequent on shared objects | Rare, because edits land in separate files |
| Scope of a deploy | Whatever `package.xml` lists | Whatever you point the CLI at |
| Typical consumer | Legacy tools, Metadata API clients | Salesforce CLI, IDE extensions, CI pipelines |
Metadata API format mirrors what the Metadata API sends and receives. It is a transport shape. Source format is an authoring shape. It trades a direct match with the API for files that people can review and merge.
Decision flow
Ask these questions in order. The first one that applies usually settles the choice.
Scenario 1: Team development with version control
Choose source format.
Suppose two developers add different fields to Account on separate branches. In Metadata API format, both edits land in Account.object. Git sees two changes to the same large file and often reports a conflict. In source format, each field is its own file:
force-app/main/default/objects/Account/fields/Rating_Notes__c.field-meta.xml
force-app/main/default/objects/Account/fields/Region_Code__c.field-meta.xmlThe branches touch different files, so the merge succeeds without manual work. Code review improves as well. A reviewer sees a new field as a new file rather than a changed block inside a file with thousands of lines.
Scenario 2: Deploying from a CI pipeline
Choose source format in the repository. Deploy it directly.
sf project deploy start --source-dir force-app --test-level RunLocalTests --wait 30You do not need to convert first. The CLI reads sfdx-project.json, finds the package directories, and handles the translation to the Metadata API internally. Adding a conversion step creates a second copy of your metadata that can drift or be committed by mistake.
If you need to deploy only a subset, point --source-dir at a folder or use --metadata with type and member names. You still stay in source format.
Scenario 3: Legacy tooling and external requirements
Choose Metadata API format at the boundary.
Some tools only accept a package.xml and its folders. Examples include older build scripts, third-party release tools, and some packaging workflows. In these cases, convert on demand and treat the result as a build artifact:
sf project convert source --root-dir force-app --output-dir mdapi_output
sf project deploy start --metadata-dir mdapi_output --wait 10Do not commit mdapi_output. Generate it in the pipeline, use it, and discard it. The repository keeps one source of truth.
Scenario 4: Migrating an existing Metadata API repository
Convert once, then switch the team over.
sf project convert mdapi --root-dir src --output-dir force-appBefore you commit the result, check three things:
sfdx-project.jsonexists and listsforce-appas a package directory.- The
sourceApiVersionmatches the version in your oldpackage.xml, unless you deliberately want a change. - A deploy of the converted source to a scratch org or sandbox succeeds.
After the switch, retire the old layout. A repository that holds both formats invites edits to the wrong copy.
Scenario 5: Exploring or retrieving metadata once
Either format works. Use whichever your tool produces by default.
If you want to inspect what an org contains, retrieve with a manifest:
sf project retrieve start --manifest manifest/package.xmlThis brings the files back in source format inside your project. If you use --target-metadata-dir, you get a zip in Metadata API format instead, which is useful when you need to hand the files to someone using older tooling.
Using a manifest in a source format project
A common misunderstanding is that package.xml belongs only to Metadata API format. It does not. You can keep a manifest in a source format project and use it to select what to retrieve or deploy.
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>MyClass</members>
<name>ApexClass</name>
</types>
<types>
<members>Account</members>
<name>CustomObject</name>
</types>
<version>60.0</version>
</Package>In source format the manifest is a selection list, not the layout itself. Keep it in a manifest/ folder, outside the package directories, so it is not mistaken for source. The CLI uses it to decide which components to move. The folder structure on disk stays decomposed.
Trade-offs to weigh
Decomposition and fidelity
Source format splits a custom object into many files. The CLI recombines them on deploy. Conversion is designed to be lossless, but two things can surprise you. File ordering inside generated XML can differ from what you wrote. Components you did not retrieve are simply absent, so a partial retrieve gives a partial object folder.
Tooling support
IDE extensions and CLI commands expect source format. Metadata API format needs more manual steps. If you choose the monolithic layout for a repository, you give up some convenience in exchange for compatibility with older tools. Make sure that trade is real, not assumed.
Reviewability versus file count
Source format creates many small files. A large org can produce thousands. This is a cost for file browsers and some search tools. In practice the benefit in diffs outweighs it. If file count becomes a problem, narrow the package directories or use .forceignore to leave out metadata you do not manage in Git.
Single source of truth
Whichever format you pick, pick one for the repository. A converted copy is an artifact. If it is committed, someone will edit it, and the two copies will disagree.
Common mistakes when choosing
- Committing converted output. Generated
mdapi_outputfolders end up in Git and cause confusion. Add the output folder to.gitignore. - Converting before every deploy. The CLI deploys source format directly. Conversion is needed only when a downstream tool demands it.
- Mixing formats in one directory. A
force-appfolder that holds bothAccount.objectandAccount/fields/leads to duplicate or conflicting components. - Ignoring the API version. A mismatch between the manifest
versionandsourceApiVersionchanges which metadata fields are available. Align them on purpose. - Treating a retrieve as complete. A retrieve returns only what the manifest lists. Check that the manifest covers the components you expect.
Verifying your choice
After you decide, confirm the setup works end to end:
- Convert source to Metadata API format and list the output. Confirm a
package.xmlexists at the root. - Convert the output back to a new source folder.
- Compare the new folder with the original using
git diff --no-index. Differences should be limited to formatting. - Deploy with
--dry-runto an org and check that no component fails.
sf project convert source --root-dir force-app --output-dir mdapi_output
sf project convert mdapi --root-dir mdapi_output --output-dir roundtrip
git diff --no-index force-app roundtrip
sf project deploy start --source-dir force-app --dry-run --wait 10A clean round trip and a passing dry run show that the layout is sound.
Exercise
Your team keeps a repository in source format. A vendor release tool accepts only a package.xml and Metadata API folders. Describe how you would supply it with metadata, and say what you would not do.
Show answer
Convert at release time with sf project convert source --root-dir force-app --output-dir mdapi_output, give the output folder to the vendor tool, and discard it afterward. Keep source format as the only layout in the repository. Do not commit mdapi_output or edit it by hand, because that creates a second copy that can drift from the source.
Exercise
Two developers each add a field to the Account object on different branches. Why is a merge conflict more likely in Metadata API format than in source format?
Show answer
In Metadata API format, both fields are written inside the single Account.object file, so both branches change the same file and Git may report a conflict. In source format, each field has its own .field-meta.xml file, so the branches change different files and merge cleanly.