Sub topic 3
The package.xml Manifest
This chapter assumes you know the basic Salesforce metadata kinds (Apex classes, custom objects, custom fields), can read XML, and can run commands in a terminal. It builds on the earlier chapters about metadata types and Metadata API format. The aim is to read and write a package.xml correctly and to know where it still matters when you work in source format.
What the manifest does
A package.xml file is a manifest. It does not contain any metadata itself. It is a list that tells the Metadata API which components you want. The API reads the list for two operations:
- Retrieve: the manifest says what to download from an org.
- Deploy: the manifest says what is in a deployment package, so the API knows what to process.
In Metadata API format, the file sits at the root of the directory or zip file, next to folders such as classes/ and objects/. In a deploy, anything that is in the folders but not named in the manifest is ignored. Anything named in the manifest but missing from the folders usually produces an error or a warning.
Anatomy of the file
Here is a small manifest that selects one Apex class and the Account object.
<?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>The file has four kinds of element:
| Element | Meaning |
|---|---|
| `Package` | The root. The `xmlns` namespace must be exactly `http://soap.sforce.com/2006/04/metadata`. |
| `types` | One block per metadata type. A type should appear only once in a manifest. |
| `members` | A component name inside that type. A `types` block can hold many `members` lines. |
| `name` | The metadata type name, such as `ApexClass`. It is the API name of the type, not a label. |
| `version` | The API version, such as `60.0`. It appears once, after all the `types` blocks. |
Two details cause many errors. First, name comes after the members lines inside a types block by convention, and tools that generate the file always write it this way. Second, version is a decimal with one fractional digit, so write 60.0 and not 60.
Members: the names you list
The text of a members element is the component's full name. How that name is built depends on the type.
- Top-level components use their plain name. An Apex class called
MyClassisMyClass. A custom object isInvoice__c. A standard object isAccount. - Child components that live inside another component use
Parent.Child. A custom fieldRating_Notes__con Account isAccount.Rating_Notes__c, listed under the typeCustomField. - Folder-based types use
Folder/Name. These types areReport,Dashboard,DocumentandEmailTemplate. A report calledPipelinein the folderSalesReportsisSalesReports/Pipeline. The folder itself is a separate member, written justSalesReports, under the same type name.
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>Account.Rating_Notes__c</members>
<name>CustomField</name>
</types>
<types>
<members>SalesReports</members>
<members>SalesReports/Pipeline</members>
<name>Report</name>
</types>
<version>60.0</version>
</Package>Listing the folder alone retrieves only the folder definition. Listing the report retrieves the report file. If you want both, list both.
Wildcards
A member of * means "every component of this type".
<types>
<members>*</members>
<name>ApexClass</name>
</types>Wildcards are convenient, but they have limits you should know:
- Not every type supports them. Some types need explicit names.
- For
CustomObject,*retrieves custom objects, but standard objects such asAccountare not included. Name each standard object you want. - For folder-based types,
*does not reach inside the folders. List each folder and each item, as shown above. - A wildcard in a retrieve is evaluated against the org at that moment. Two retrieves from the same manifest can return different file sets if someone adds a class in between.
For repeatable work, such as a release that must match what was tested, name members explicitly. Use wildcards for exploration and for a first pull from a sandbox.
How a type relates to its children
CustomObject is special because a retrieve of an object returns its fields, record types, validation rules and similar children inside the one Account.object file. That means listing Account under CustomObject is usually enough to bring its fields along. You list CustomField separately when you want only certain fields without the whole object. Be careful here: a deploy of a whole CustomObject file replaces what the org holds for the parts included in that file, so partial object files can remove fields you did not mean to touch.
Where the version number matters
The version element sets the API version used for the operation. It decides which metadata types exist and which XML fields are valid. If you retrieve with version 60.0, the XML you get is shaped by that version. If a type was added in a later version, a manifest at an older version cannot name it. When you deploy, files written with newer fields into an older version can fail.
Keep the manifest version close to the version the org runs, and match it to sourceApiVersion in sfdx-project.json so the two do not drift.
Using the manifest with the CLI
The manifest is not tied to Metadata API format. You can use it in a source-format project as a selection list. The CLI reads the manifest, asks the org for those components, and writes them in the source-format layout.
# Retrieve the components named in the manifest into a source-format project
sf project retrieve start --manifest manifest/package.xml
# Deploy the components named in the manifest from a source-format project
sf project deploy start --manifest manifest/package.xml --wait 10This is why many teams keep a manifest/ folder in a DX project. The project itself does not need a package.xml, but a manifest is still the clearest way to say "this set of components".
You do not have to write the file by hand. The CLI can generate one from a list of types or from a folder of source files.
# Generate a manifest from metadata type names
sf project generate manifest --metadata ApexClass --metadata CustomObject --output-dir manifest
# Generate a manifest from the source files in a directory
sf project generate manifest --source-dir force-app --output-dir manifestCheck the generated file before you use it. A manifest built from a source directory lists exactly what is in that directory, which is often a good way to build a precise deploy list.
Deleting components with a destructive manifest
A package.xml only adds or updates components. To delete them, you use a second file, destructiveChanges.xml, which has the same structure but lists the members to remove. In a Metadata API format deploy, it sits beside package.xml, and package.xml must still be present, often with no types blocks.
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>OldHelper</members>
<name>ApexClass</name>
</types>
<version>60.0</version>
</Package>Deleting from a destructive manifest affects the target org immediately on a successful deploy, so check the org name before you run it.
Common manifest errors
| Symptom | Likely cause |
|---|---|
| "Entity of type X named Y cannot be found" | The member name is wrong, or the component does not exist in that org. |
| Nothing returned for a wildcard | The type does not support `*`, or it is a folder-based type. |
| Standard object missing after a retrieve | `*` under `CustomObject` skips standard objects. List `Account` and others by name. |
| "Unknown type name" or an invalid-element message | The type is newer than the manifest `version`, or `name` has a typo or the wrong case. |
| Report or dashboard not found | The folder, or `Folder/Name`, is not listed. |
| A deploy ignores a file | The component is in the folders but not in `package.xml`. |
Type names are case sensitive. ApexClass works, and apexclass does not.
Exercise
You need to retrieve the field RatingNotes_c on Account, the folder SalesReports, and the report Pipeline inside it. Which members and type names do you list in the manifest?
Show answer
Use three members under two type blocks. Under CustomField list Account.RatingNotes_c. Under Report list SalesReports (the folder) and SalesReports/Pipeline (the report). The manifest also needs the version element, for example 60.0, after the types blocks.
Exercise
A teammate used a CustomObject wildcard to retrieve all objects, but Account and Contact are missing. Why, and how do you fix the manifest?
Show answer
The wildcard on CustomObject returns custom objects only. Add explicit members Account and Contact under the CustomObject type, alongside the wildcard if you still want all custom objects.