Sub topic 7
Retrieving with a Manifest
This chapter assumes you can run sf commands, have a Salesforce DX project, and have already authorized an org. You should also know how to retrieve a single component by name. Here you will retrieve a whole set of components in one command, using a package.xml manifest.
Why use a manifest
Retrieving by name works well for one or two components. It gets awkward when you need dozens, or when you want to repeat the same retrieval later. A manifest is a file that lists the components you want. You can keep it in Git, review it, and run it again.
A manifest has a <types> block for each metadata type. Each block lists members (component names) and the type name. The <version> element sets the API version used for the retrieve.
The manifest
This manifest selects every Apex class and the Invoice__c custom object.
<?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>The * wildcard means "all components of this type". A named member selects only that component. Save the file as manifest/package.xml in your project.
Running the retrieve
Pass the manifest with --manifest. Name the org with --target-org, or omit the flag to use your default org.
sf project retrieve start --manifest manifest/package.xml --target-org my-sandboxThe CLI retrieves exactly the components the manifest lists. It writes them into your package directories in source format. If a file already exists locally, the retrieved version replaces it.
Common errors
Most problems come from the manifest, not the command.
- A misspelled type or member.
CustomObjectsinstead ofCustomObjectreturns an error or nothing. Use the exact metadata type name. - A member that does not exist in the org. The CLI reports a warning for that member. The rest of the retrieve still completes, so read the output.
- A wildcard that does not cover everything. Some types, such as
ReportandDashboard, need folder names as members, because*does not reach inside folders. Check the Metadata API documentation for the type. - Files filtered out. A match in
.forceignorekeeps a retrieved file out of your project. If a component seems missing, check that file. - No default org. Without
--target-orgor a configured default, the command fails. Set one withsf config set target-org.
Name or manifest
| Situation | Better choice |
|---|---|
| One or two components, one time | `--metadata` |
| A repeatable set of components | `--manifest` |
| A list you want in version control | `--manifest` |
Exercise
You run a manifest retrieve and the output warns that one named member was not found, yet other components were retrieved. What does that tell you, and what should you check?
Show answer
The retrieve is partial: components that exist were retrieved, and the missing member was skipped. Check the spelling of the member and its type in the manifest, and confirm the component exists in the target org you named (or your default org).
Exercise
Your manifest lists <members>*</members> for Report, but no reports appear in your project. Why, and how do you fix it?
Show answer
The wildcard does not reach reports stored in folders. List the folder names, and the reports inside them, as members of the Report type instead.