Sub topic 12
Choosing the right format for your workflow
This chapter assumes you know what a package.xml manifest is, how source format splits a custom object into files, and how sf project convert works. Here you will decide which format fits a given job. The answer is usually "both, at different points."
What each format is good at
Metadata API format groups components by type. Each component is one file, and a package.xml manifest selects which ones to deploy. Source format is the Salesforce DX layout. It splits large components, such as custom objects, into many small files under the package directories listed in sfdx-project.json.
| Concern | Metadata API format | Source format |
|---|---|---|
| Version control diffs | Large files. One field change can alter a big `Account.object` file. | Small files. One field is one `.field-meta.xml` file. |
| Merge conflicts | More likely, because many edits land in the same file. | Less likely, because edits are spread across files. |
| Selecting what to deploy | `package.xml` lists types and members. | Paths, metadata names, or manifests. |
| Project marker | `package.xml` | `sfdx-project.json` |
| Legacy tooling | Widely supported. | Needs Salesforce DX-aware tools. |
A decision flow
Start from what you need to do, then follow the arrows.
Scenario 1: Day-to-day development and version control
Use source format. Reviewers see small, isolated diffs. For example, adding Rating_Notes__c creates one new file, force-app/main/default/objects/Account/fields/Rating_Notes__c.field-meta.xml. Two developers who add different fields to Account will not edit the same file.
Source format is also what the sf project deploy start and sf project retrieve start commands expect by default when they run inside a project with sfdx-project.json.
Scenario 2: Working with legacy tooling
Some older tools and scripts only accept a Metadata API directory with a package.xml. Examples include older build pipelines and ZIP-based deployment steps. Keep your repository in source format and convert at the edge of the pipeline:
sf project convert source --root-dir force-app --output-dir mdapi_output
sf project deploy start --metadata-dir mdapi_output --wait 10The converted directory is a build artifact. Do not commit it as a second source of truth.
Scenario 3: Migrating an older repository
If a repository holds Metadata API format files, convert it once and commit the result as source format:
sf project convert mdapi --root-dir mdapi_output --output-dir force-appThen confirm that sfdx-project.json lists force-app as a package directory. After the migration, make source format the only format that developers edit.
Scenario 4: Deploying a one-off set of components
If you already have a curated package.xml, such as a shared release manifest, the manifest-driven approach is a good fit. The same manifest can drive a retrieve or a deploy in either format, so a manifest does not force you into Metadata API format.
Criteria to apply
Ask these questions in order:
- Do people edit this metadata and review it in Git? If yes, choose source format.
- Does a downstream tool require a
package.xmldirectory? If yes, convert at that boundary and treat the output as disposable. - Is there already an established project? If yes, follow its existing format unless you have a reason to migrate. Mixing both formats in one repository makes it unclear which files are authoritative.
Verify your choice
After any conversion, check the result before you rely on it:
- Count components of a type in both layouts and compare, for example Apex classes.
- Confirm each class has both its
.clsfile and its.cls-meta.xmlcompanion. - For converted objects, confirm that field files appear under
objects/<Object>/fields/.
Exercise
Your team keeps a repository in source format. A release pipeline step accepts only a Metadata API directory containing package.xml. Which approach do you take, and should the converted directory be committed?
Show answer
Keep the repository in source format and run sf project convert source --root-dir force-app --output-dir mdapi_output in the pipeline, then deploy with sf project deploy start --metadata-dir mdapi_output. Do not commit the converted directory. It is a generated artifact, and committing it creates a second copy that can drift from the source.
Exercise
A teammate says that using a package.xml means the project must be in Metadata API format. Is this correct?
Show answer
No. A manifest only selects which components to deploy or retrieve. It can be used with a source format project. The directory layout is a separate choice.