Sub topic 6
Writing and Generating a package.xml Manifest
This chapter assumes you have a Salesforce DX project, an authorized org, and have run a basic sf project retrieve start with --metadata. It covers the manifest file that lets you select components in one reusable place.
What a manifest is
A manifest is an XML file, usually named package.xml, that lists the metadata components you want to retrieve or deploy. Naming components on the command line works for a few items. A manifest scales better, and you can commit it to Git so a team shares the same selection.
By convention, a DX project keeps manifests in a manifest directory.
The structure
Each <types> block names one metadata type in <name> and lists the components of that type in <members>. A single <version> element sets the 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>This manifest selects every Apex class, because * is a wildcard that matches all components of that type. It also selects the single custom object Invoice__c. The version 60.0 is the API version used for the operation.
Rules to remember
- The
<name>value is the metadata API type name, such asApexClassorCustomObject, not a folder name. - You can list several
<members>in one<types>block. - The wildcard does not work for every type. Some types, such as
StandardValueSet, need explicit names. If a wildcard returns nothing, check the type's documentation. - Members of folder-based types, such as reports, use the form
FolderName/ReportName.
Writing a manifest by hand
Create manifest/package.xml in your project and paste the structure above. Then edit the types and members you need. Writing by hand is fine for small, stable lists.
Generating a manifest
Typing every member is error-prone. The CLI can generate one for you with sf project generate manifest.
sf project generate manifest --metadata ApexClass --metadata CustomObject:Invoice__c --output-dir manifestYou can also build a manifest from source you already have locally:
sf project generate manifest --source-dir force-app --name my-packageThe first command writes manifest/package.xml from the names you give. The second reads every component under force-app and writes manifest/my-package.xml. If you omit --name, the file is called package.xml.
How the manifest fits into the workflow
The same file drives both directions. Retrieving pulls the listed components from the org into your project, and deploying pushes the local versions of those components to the org.
Common errors
| Symptom | Likely cause |
|---|---|
| Retrieve returns no components | Wrong type name, or a wildcard on a type that does not support it |
| "Entity of type ... not found" warning | A member name has a typo or does not exist in the org |
| XML parse error | Missing closing tag or wrong namespace on `<Package>` |
Exercise
A manifest contains a <types> block with <members>*</members> and <name>ApexClass</name>. What does it select, and which element sets the API version?
Show answer
It selects every Apex class in the org (for retrieve) or in the project source (for deploy). The <version> element at the end of the <Package> sets the API version.
Exercise
Which command generates manifest/package.xml from the source already in force-app?
Show answer
sf project generate manifest --source-dir force-app --output-dir manifest. Without --name, the file is called package.xml.