Sub topic 3
Deploying and Retrieving in Each Salesforce Metadata Format
Assume you know Apex classes, custom objects, XML, basic Git, and command-line navigation. The main difference is the path you give the Salesforce CLI and the format expected by the surrounding tools.
Deploying and retrieving
Source format uses a Salesforce DX project directory, usually force-app/main/default. Metadata API format uses a directory containing package.xml and metadata-type folders.
# Deploy source format
sf project deploy start --source-dir force-app/main/default --target-org my-org --wait 10
# Retrieve Metadata API format
sf project retrieve start --manifest package.xml \
--target-metadata-dir mdapi_output --target-org my-org --wait 10
# Deploy Metadata API format
sf project deploy start --metadata-dir mdapi_output \
--target-org my-org --wait 10A source-format retrieve writes decomposed files into the project. A manifest-based retrieve writes the selected components into Metadata API format.
Bundles and static resources
Some metadata is naturally a bundle: one component contains several related files. Static resources can be a single resource file or an archive. Other bundles, such as Experience Cloud or Aura components, use directories with required internal files.
Conversion preserves the bundle boundary. Do not rename or separate files inside a bundle unless the metadata type supports that layout.
Controlling files with .forceignore
The .forceignore file excludes local paths from source-aware Salesforce CLI operations. Typical entries exclude generated output, logs, and local tooling files.
mdapi_output/**
*.log
.history/**Ignoring a file does not delete metadata from an org. It only changes which local files the CLI considers.
Choosing a format
Use source format for Git, code review, Salesforce DX projects, and small isolated changes. Use Metadata API format when a legacy tool requires package.xml, when handing off a monolithic deployment package, or when working with tooling that does not understand decomposition.
Common pitfalls and verification
Common failures include using the wrong API version, omitting package.xml members, moving a -meta.xml file away from its component, and treating a bundle as ordinary files. After conversion, inspect the directory tree and compare the result with Git.
sf project convert source --root-dir force-app --output-dir mdapi_output
git diff --check
sf project convert mdapi --root-dir mdapi_output --output-dir converted_sourceA clean conversion should preserve component names, metadata types, and bundle contents.
Exercise
Which format is usually better for version control, and why?
Show answer
Source format is usually better because decomposition gives each component, field, and companion metadata file a small, focused diff.