Sub topic 2
Retrieving and Deploying with `--manifest`
Assume you know basic Salesforce metadata types, XML, and the sf CLI. A manifest is a package.xml file that tells Salesforce which metadata components to retrieve or deploy. Each component belongs to a metadata type and has a member name.
Retrieve and Deploy with a Manifest
Use --manifest to retrieve or deploy exactly the components listed in the file:
sf project retrieve start \
--manifest manifest/package.xml \
--target-org my-sandbox
sf project deploy start \
--manifest manifest/package.xml \
--target-org my-sandboxA retrieve copies metadata from the org into the local project. A deploy sends local metadata to the org. The manifest must use a Metadata API version supported by the target org.
Writing a Destructive Changes File
A destructive changes file has the same XML structure as package.xml, but its members are components to delete. Use exact metadata member names.
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>LegacyAccountService</members>
<name>ApexClass</name>
</types>
<types>
<members>Account.OldRegion__c</members>
<name>CustomField</name>
</types>
</Package>The file deletes an Apex class and a custom field. A wildcard such as * is not supported in destructive changes files.
Pre Versus Post Destructive Changes
Pre-destructive changes run before the components in package.xml are deployed. Use them when an old component must be removed before a replacement can be deployed.
Post-destructive changes run after the regular deployment. Use them when the old component must remain available while new or changed components are deployed.
Running a Destructive Deployment
Pass the destructive file with the matching CLI option:
sf project deploy start \
--manifest manifest/package.xml \
--post-destructive-changes manifest/destructiveChangesPost.xml \
--target-org my-sandboxFor a delete-only deployment, package.xml can contain only the API version:
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<version>62.0</version>
</Package>Validate in a sandbox first with --dry-run. If deletion fails, check dependencies such as references from flows, permission sets, layouts, or Apex code. Also verify capitalization, namespace prefixes, object names, and field names.
Exercise
Which option should you use when a component must be deleted before the components in package.xml are deployed?
Show answer
Use --pre-destructive-changes.