Destructive Changes Deployment
This skill activates when a practitioner or agent needs to delete metadata components from a Salesforce org using Metadata API or the sf CLI. It covers all three manifest variants, dependency sequencing, components that cannot be deleted via API, and the correct CLI flags.
Before Starting
Gather this context before working on anything in this domain:
- Confirm the exact API name and metadata type of every component to be deleted. Wildcards are not supported in destructiveChanges manifests — every member must be listed explicitly.
- Identify all components that reference the target component. A deletion will fail with a deployment error if any active component still holds a reference (e.g., a field referenced in a validation rule, a class referenced in a trigger, a component embedded in an active Lightning page).
- Know which components need manual Setup work before or instead of a destructive deploy: an active Flow version can't be deleted (api_meta.txt L68041), and picklist field values are not standalone manifest members. Record Types are not in this list: the RecordType type is documented to "create, update, or delete record type definitions for a custom object" (api_meta.txt L44970). UNVERIFIED (2026-10-19): practitioners report destructive deletes of record types still assigned to records or profiles failing; reassign and deactivate first and prove the delete in a sandbox.
Questions to Ask Before Configuring
| Ask | Why it matters | What a good answer adds |
|---|---|---|
| Are the destructive manifests hand-written, or copied from an existing package.xml? | A copied manifest drags in a <version> element; the version belongs in the companion package.xml, which must sit in the same directory. | Produces a destructive manifest with explicit members and no version, plus a version-only package.xml (Gotcha 1). |
| Does any deletion depend on an update in the same deploy clearing a reference first, such as a class that still uses the object? | Plain destructiveChanges.xml deletions run before additions, so the reference is still there when the delete runs. | Puts that member in destructiveChangesPost.xml (Gotcha 2). |
| Is any component deleted and re-created under the same name in this release? | Plain destructiveChanges.xml and the Pre variant both delete before additions (api_meta.txt L4648); only Post deletes after. | Names the variant on purpose instead of relying on the plain file (Gotcha 2). |
| How will other branches, local projects and the CI pipeline learn that these files are gone? | A stale local file redeployed later brings the deleted component back. | Deletes the source files in the same PR and adds retrieve-before-deploy or source tracking (Gotcha 3). |
| Does any flow on the list have an active version in the target org? | A flow with an active version cannot be deleted through a deploy, and the error may name it by internal ID. | Adds a deactivation step before the destructive deploy (Gotcha 4). |
| Does the cleanup include record types or picklist values, global value sets included? | Picklist values are not manifest members and need Setup work; record types are documented as deletable for custom objects (api_meta.txt L44970), but in-use ones are reported to fail (UNVERIFIED (2026-10-19)). | Moves them to a manual runbook step with an owner and a date (Gotcha 5). |
| Is any object or component on the list used by an active Lightning page or its action override? | Items tied to an active Lightning page can't be deleted by destructiveChanges.xml. | Adds the Lightning App Builder deactivation as a pre-deploy step (Gotcha 6). |
A proper configuration orders every deletion and lists the manual steps before the deploy, so the release removes exactly what was planned and nothing comes back on the next deploy.
Core Concepts
The Three Manifest Variants
The Metadata API supports three placements for destructive operations within a deployment, each controlled by the filename. All three files share the same XML schema as a standard package.xml.
destructiveChangesPre.xml — Deletions are processed before the additions and updates in the accompanying package.xml. Use this when the component being deleted would conflict with a new component being deployed (e.g., renaming a field by deleting the old one and creating the new one, where the old name must be cleared first).
destructiveChanges.xml (plain name) — The platform processes deletions at the same time as additions. In practice this behaves like a pre-deployment deletion. This is the legacy format from the Ant Migration Tool era and remains valid.
destructiveChangesPost.xml — Deletions are processed after all additions and updates in package.xml have landed. This is the required variant when the component being deleted is still referenced by another component that is itself being updated in the same deployment. The new version of the referencing component must land first (clearing the reference) before the deleted component can be removed.
All three files must be included inside the same deployment package as a package.xml. When using sf CLI flags, an empty package.xml (specifying only the API version) may be used as the companion manifest.
Manifest XML Structure
Every destructive manifest follows the same schema as package.xml. The <version> element is omitted from destructive manifests — version lives only in package.xml. Each <types> block groups members by metadata type.
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>MyObject__c.OldField__c</members>
<name>CustomField</name>
</types>
<types>
<members>OldValidationRule</members>
<name>ValidationRule</name>
</types>
</Package>
Member names must use the same format as they appear in package.xml — for child metadata types like CustomField, the format is ParentObject.FieldName.
sf CLI Flags for Destructive Deployments
The sf project deploy start command (Salesforce CLI v2) exposes two flags:
--pre-destructive-changes <path>— points to adestructiveChangesPre.xmlfile to process before deploying the--manifest.--post-destructive-changes <path>— points to adestructiveChangesPost.xmlfile to process after deploying the--manifest.
Example using pre-destructive:
sf project deploy start \
--manifest package.xml \
--pre-destructive-changes destructiveChangesPre.xml \
--target-org myOrgAlias
The --manifest flag is required even when the package.xml contains no components to add; in that case use an API-version-only manifest.
Components That Cannot Be Deleted via API
The following need manual work in Setup instead of, or before, a destructive manifest:
- Record Types — the RecordType type documents delete for custom-object record types (api_meta.txt L44970). UNVERIFIED (2026-10-19): deletes of record types still assigned to records or profiles are reported to fail; reassign, deactivate, and prove the delete in a sandbox first.
- Picklist values — field values are not standalone members of a destructive manifest. UNVERIFIED (2026-10-19): they cannot be removed via API at all. Use the Replace Picklist Values feature or manual field editing.
- Active Flow versions — an active version of an Autolaunched or Screen Flow cannot be deleted via deployment. Deactivate the flow in Setup first, then delete.
Attempting to delete these via a manifest results in a deployment error. The error message is not always obvious about the root cause.
Common Patterns
Pattern 1 — Delete a standalone component with no inbound references
When to use: Removing a custom object, Apex class, Lightning Web Component, or custom metadata type that has no active references in other deployed components.
How it works:
- Confirm zero inbound references using Setup dependency tooling or
sf project retrieve startto inspect local source. - Build
destructiveChanges.xmllisting the component. - Create an empty companion
package.xmlcontaining only the API version. - Deploy using
sf project deploy start --manifest package.xml --pre-destructive-changes destructiveChanges.xml --target-org alias.
Why not the alternative: Deploying without an empty package.xml companion will cause a deployment error — the Metadata API requires a valid package manifest in the deployment container.
Pattern 2 — Delete a component that is still referenced (use Post variant)
When to use: Removing a custom field or class that is still referenced by another component, where the referencing component is also being updated in the same deployment to remove the reference.
How it works:
- Build the updated referencing component (e.g., updated Apex class with reference removed, updated validation rule formula, updated page layout).
- Include the updated component in
package.xml. - Place the deletion in
destructiveChangesPost.xml. - Deploy: the updated component lands first (clearing the reference), then the deletion fires.
sf project deploy start \
--manifest package.xml \
--post-destructive-changes destructiveChangesPost.xml \
--target-org alias
Why not the alternative: Using destructiveChangesPre.xml or plain destructiveChanges.xml in this scenario causes the deletion to fire before the reference is cleared, producing a deployment failure.
Pattern 3 — Troubleshooting a failing destructive deployment
When to use: A destructive deployment is failing and the error is not immediately clear.
How it works:
- Read the deployment error message carefully. Common patterns: "Component in use by...", "Cannot delete...", "Component not found".
- "Component in use" — find the referencing component and either update it first (use post variant) or remove the reference in a prior deployment.
- "Cannot delete" on an active Flow (api_meta.txt L68041), an in-use Record Type, or a Picklist value — handle manually in Setup.
- "Component not found" — the API name or type is wrong in the manifest; re-check exact casing and type name.
- Run the checker script:
python3 scripts/check_destructive.py --manifest-dir <path>.
Decision Guidance
| Situation | Recommended Approach | Reason |
|---|---|---|
| Deleting a component with no active references | destructiveChanges.xml or --pre-destructive-changes | Simplest case; no ordering concern |
| Deleting a component that is still referenced, and clearing the reference in the same deploy | destructiveChangesPost.xml via --post-destructive-changes | Reference must be removed before deletion fires |
| Deleting a component whose API name conflicts with a new component being added | destructiveChangesPre.xml via --pre-destructive-changes | Old component must be cleared before new one can land |
| Deleting a Picklist value or an active Flow version; a Record Type still in use | Manual Setup action (deactivate the flow first) | Active flow versions can't be deleted (api_meta.txt L68041); record-type behaviour is UNVERIFIED (2026-10-19) beyond the documented delete support (L44970) |
| Deleting many components across multiple types | Single manifest with multiple <types> blocks | Metadata API processes all members in one transaction |
Recommended Workflow
Step-by-step instructions for an AI agent or practitioner working on this task:
- Inventory components to delete — List every component by exact metadata type and API name. Confirm no wildcards are being used (they are not supported in destructive manifests).
- Check dependencies — For each component, determine whether any other active component references it. Use Setup dependency tooling, org-wide metadata retrieval, or
sf project retrieve startto inspect locally. - Choose the correct manifest variant — Use
destructiveChangesPost.xmlif the referencing component is being updated in the same deployment. UsedestructiveChangesPre.xmlordestructiveChanges.xmlfor standalone deletions. Never attempt to delete Record Types, Picklist values, or active Flow versions via manifest. - Build the manifest — Author the XML with correct
<types>and<members>entries. Do not include a<version>element. Pair with a valid companionpackage.xml(even if empty of components, it must specify the API version). - Run the checker script — Execute
python3 scripts/check_destructive.py --manifest-dir <path>to surface common authoring mistakes before deploying. - Deploy and validate — Run
sf project deploy startwith the appropriate flag. Check the deployment status output. If errors occur, map them to the known failure modes in Pattern 3. - Verify deletion in target org — Confirm the component no longer appears in Setup or metadata retrieval. Check that no unexpected cascading deletions occurred.
Review Checklist
Run through these before marking work in this area complete:
- [ ] Every component in the manifest is listed by exact API name with no wildcards
- [ ] Manifest variant (pre/post/plain) matches the dependency ordering requirement
- [ ] No undeletable component types (Record Types, Picklist values, active Flows) are in the manifest
- [ ] A valid companion
package.xmlis included in the deployment container - [ ] The correct sf CLI flag (
--pre-destructive-changesor--post-destructive-changes) is used - [ ] Checker script was run and returned no issues
- [ ] Deletion confirmed in target org after deployment
Salesforce-Specific Gotchas
Non-obvious platform behaviors that cause real production problems:
- Wildcards silently fail — Unlike
package.xml, wildcards (*) in a destructive manifest do not delete all components of a type. The wildcard is treated as a literal member name and the deployment will either fail or silently skip the deletion. List every member explicitly. - Post manifest required even when both changes are in the same deploy — Practitioners often assume that listing both the deletion and the updated referencing component in the same deployment is sufficient regardless of manifest type. The pre/plain variant fires the deletion first, before the updated component lands, causing the "still referenced" error even though the fix is in the same package.
- Deleted components may be re-created by a subsequent retrieve — If a team member runs
sf project retrieve startafter the deletion without updating their local source, the deleted component re-appears in the local project and may be re-deployed in the next push, undoing the deletion in the org.
Output Artifacts
| Artifact | Description |
|---|---|
| destructiveChangesPre.xml | Manifest of components to delete before additions; paired with package.xml |
| destructiveChangesPost.xml | Manifest of components to delete after additions; use when deleted component is still referenced by a component being updated in the same deploy |
| destructiveChanges.xml | Plain (simultaneous) variant; legacy format, still valid |
| package.xml (companion) | Required companion manifest; may contain no members but must specify the API version |
Related Skills
metadata-api-and-package-xml— use forpackage.xmlauthoring, metadata type reference, and retrieval patterns; the destructive manifest schema mirrors this skill's package manifest structurechange-set-deployment— use for UI-driven deployment workflows; change sets do not support destructive changes natively