Sub topic 11
Backing up metadata with a manifest
Records are only half of a Salesforce backup. Metadata describes how the org is built: custom objects, fields, Apex classes, flows, page layouts, and permission sets. Data exports such as the Data Export Service or Data Loader do not capture any of it. This chapter shows how to retrieve metadata with a manifest and keep it in version control.
This chapter assumes you have the Salesforce CLI installed, an authorized org alias, and basic Git knowledge. It also assumes you can read a short XML file.
Why metadata needs its own backup
Without metadata, a restored set of records has nowhere to go. If a custom field was deleted, its CSV column cannot be loaded back. Metadata is also the part of the org that changes through deployments, so a history of it is useful beyond disaster recovery. It lets you see what changed and when.
The package.xml manifest
A manifest is an XML file that lists the metadata types you want to retrieve. Each types block names one type and its members. A * member means all components of that type.
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>*</members>
<name>CustomObject</name>
</types>
<types>
<members>*</members>
<name>ApexClass</name>
</types>
<types>
<members>*</members>
<name>Flow</name>
</types>
<version>60.0</version>
</Package>The version element sets the metadata API version used for the retrieve. Save the file as manifest/package.xml inside a Salesforce DX project.
Retrieving into a DX project
Run the retrieve from the project root:
sf project retrieve start \
--manifest manifest/package.xml \
--target-org my-prod-aliasThe CLI writes the components as source files under the project's package directory, usually force-app. Each component becomes its own file, which makes Git diffs readable.
Storing the result in version control
After the retrieve, commit the files. A new commit on each run gives you a change history.
git add force-app manifest
git commit -m "Metadata backup $(date +%Y-%m-%d)"
git pushCommon errors
- Missing types. A manifest only retrieves what it lists. New metadata types are not picked up until you add them, so review the file when you adopt new features.
- Wildcards that do not work. Some types need explicit member names rather than
*. If a type returns nothing, list its members by name. - Retrieving from the wrong org. Check the alias before running. A retrieve from a sandbox will overwrite your files with sandbox state.
- Secrets in the repository. Metadata can include named credentials settings and endpoint URLs. Use a private repository with restricted access.
Exercise
Your manifest lists CustomObject and ApexClass with a * wildcard. A teammate adds a new flow to production. Will the next scheduled retrieve back it up, and what should you change?
Show answer
No. A manifest only retrieves the types it lists, and Flow is not listed. Add a types block with <members>*</members> and <name>Flow</name>, then run the retrieve again and commit the new files.