Sub topic 2
Writing and Using a `package.xml` Manifest
Assume you know basic command-line use, Salesforce metadata, Git, and the Salesforce CLI. You also need an authorized org and a Salesforce DX project.
Write a manifest
A manifest is a package.xml file that selects metadata by type and name. The members element identifies components. The name element identifies the metadata type. The version element sets the Metadata API version.
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>*</members>
<name>ApexClass</name>
</types>
<types>
<members>Invoice__c</members>
<name>CustomObject</name>
</types>
<version>60.0</version>
</Package>An asterisk selects every component of that type. A specific member, such as Invoice__c, selects only that component. Keep manifests in a directory such as manifest/. You can also generate one from an org:
sf project generate manifest --from-org my-sandbox --output-dir manifestReview a generated manifest before using it. It may include dependencies or components that you did not intend to move.
Retrieve with a manifest
Use the manifest when you need an explicit, repeatable selection:
sf project retrieve start --manifest manifest/package.xml --target-org my-sandboxThe CLI converts Metadata API results into the DX source format in your project. A manifest is useful for release subsets, backups, and scripted retrievals.
| Selection method | Best use |
|---|---|
| Source directory | Retrieve a known project area |
| Metadata name | Retrieve a few named components |
| `package.xml` | Repeat an exact metadata selection |
flowchart TD
A[package.xml] --> B[Metadata API selection]
B --> C[Retrieve into DX source]
B --> D[Deploy selected metadata]caption: A manifest selects metadata for retrieval or deployment. alt: A package.xml manifest feeds a metadata selection, which can retrieve source or deploy it.
Deploy and preview
To deploy local source, specify a source directory:
sf project deploy start --source-dir force-app --target-org my-sandbox --dry-runThe --dry-run option validates the deployment without saving changes. Remove it when the preview succeeds:
sf project deploy start --source-dir force-app --target-org my-sandboxUse a manifest instead when the deployment must contain only its listed components. Check the target org and test level before deploying shared or production environments.
Exercise
Which command retrieves exactly the components listed in manifest/package.xml?
Show answer
sf project retrieve start --manifest manifest/package.xml --target-org my-sandbox