Sub topic 3
The package.xml manifest
This chapter assumes you know what a metadata type is, such as ApexClass or CustomObject. It also assumes you can read XML and run basic CLI commands. The manifest is a plain XML file that selects which components a retrieve or deploy touches.
What the manifest does
In Metadata API format, package.xml sits at the root of the directory. It does not hold the metadata itself. It lists which components the operation covers, and it sets the API version.
On retrieve, the manifest tells the org what to send back. On deploy, it tells the org which files in the directory to apply. A file that exists in the directory but is not listed in the manifest is ignored.
Structure of the file
Here is a minimal manifest.
<?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><types>is one block per metadata type. The order of blocks does not matter.<name>holds the metadata type name. It is case-sensitive and must match the API name exactly.<members>holds one component per element. Repeat it to list several.<version>is the API version for the operation. It decides which fields and types are available.
Choosing members
You can list members by name, or you can use a wildcard.
<types>
<members>*</members>
<name>ApexClass</name>
</types>* selects every component of that type. Wildcards are convenient for broad retrieves, but they make deploys less predictable, because you deploy whatever happens to be in the directory.
Some types need a specific naming form:
| Type | Member form | Example |
|---|---|---|
| `ApexClass` | Component name | `MyClass` |
| `CustomObject` | Object API name | `Account`, `Invoice__c` |
| `CustomField` | Object, a dot, then field | `Account.Rating_Notes__c` |
| `Report` | Folder, a slash, then report | `SalesReports/Pipeline` |
CustomField is a separate type from CustomObject. Listing Account under CustomObject retrieves the object, and that includes its fields. To select one field, use the CustomField form instead.
Generating a manifest
You can write a manifest by hand. The CLI can also generate one from your project's source directory:
sf project generate manifest --source-dir force-app --name package.xmlYou can then use the file to retrieve from an org:
sf project retrieve start --manifest package.xmlCommon errors
- A misspelled type name.
Apexclassis notApexClass. The operation fails or silently selects nothing. - A member that does not exist. A retrieve returns a warning and leaves that component out. A deploy fails.
- A missing folder prefix. Reports, dashboards, documents, and email templates live in folders. The member must include the folder path.
- Assuming the version is harmless. An old
<version>can hide newer fields. A new version can fail against an org that does not support it. - Wrong placement. In Metadata API format,
package.xmlmust be at the root of the deployed directory. A manifest buried in a subfolder is not found.
Exercise
You want to retrieve only the field Rating_Notes__c on Account, not the whole object. Which <name> and <members> values do you use?
Show answer
Use <name>CustomField</name> with <members>Account.Rating_Notes__c</members>. Listing Account under CustomObject would retrieve the entire object instead of the single field.
Exercise
A deploy of a Metadata API format directory ignores a class file that is present in the classes/ folder. What is the most likely cause in the manifest?
Show answer
The class is not listed under ApexClass in package.xml, and no wildcard covers it. Files not selected by the manifest are not deployed.