Skip to main content
skill CX Codex

platform-destructive-deploy — Claude Code skill for Salesforce deletions

A skill that walks an agent through removing Salesforce metadata: reference scan first, validation second, deploy after that.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add forcedotcom/sf-skills --skill platform-destructive-deploy -a claude-code
Open on GitHub

What platform-destructive-deploy does

Use it when a component has to leave the org rather than the local disk. The agent collects metadata types and API names, greps force-app/ for mentions of each one, and reports what still points at it. Blind deletion is off the table. If something references the component, you either fix those spots first or remove them in the same destructive deploy.

Next comes the manifest: manifest/destructiveChangesPre.xml or destructiveChangesPost.xml, validated with sf project deploy validate and --test-level RunLocalTests. The API version comes from sfdx-project.json. On production the sf-deploy-gate classifier resolves the org type first, then the agent lists every component to be deleted and waits for an explicit confirmation. A sf-deploy-gate destructive hook blocks bare destructive commands against prod, and the skill treats that denial as final.

You need the Salesforce CLI and an authorized org; a package.xml descriptor has to sit next to the destructive manifest for a deletion-only run. --purge-on-delete appears only on a direct request, because without it the data is still recoverable from the recycle bin. Removing a field marked required="true" or one used in RecordType picklist values has knock-on effects elsewhere, and the skill has to flag them before running anything.

What it helps with

  • delete a custom object or field from the org, not from disk
  • find code and flows that reference an Apex class before removing it
  • test a destructive deploy on a sandbox first
  • run a deletion alongside a regular metadata package
  • clean up local source files after a successful removal

Example prompts for the agent

  • Delete the custom field Account.Status__c from the org with a destructive deploy
  • Run a destructive deploy for MyController and OldThing__c, validate before executing
  • Remove these components from production, show me the list and wait for my confirmation

How to install platform-destructive-deploy

1Skills CLI (Vercel)

npx skills add forcedotcom/sf-skills --skill platform-destructive-deploy -a claude-code

2Manually: put the files in place

~/.claude/skills/platform-destructive-deploy/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/platform-destructive-deploy/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about platform-destructive-deploy

How do I install platform-destructive-deploy in Claude Code?

Run npx skills add forcedotcom/sf-skills --skill platform-destructive-deploy -a claude-code. The skill then lives at ~/.claude/skills/platform-destructive-deploy/SKILL.md.

What does platform-destructive-deploy do?

It coordinates metadata removal from a Salesforce org through a destructiveChanges.xml manifest: scan for references, validate, then execute the deploy.

Why does production need confirmation?

The sf-deploy-gate destructive hook stops destructive commands aimed at production, and the skill must list what will be deleted and get an explicit go-ahead.

Source text

SKILL.md · Apache-2.0
---
name: platform-destructive-deploy
description: "Execute the destructiveChanges.xml delete-and-deploy workflow against a Salesforce org. TRIGGER when the user asks to delete/remove a custom object, field, Apex class, flow, or any metadata component FROM an org, or to perform a 'destructive deploy' / removal as part of a release. Validates first and gates production with explicit confirmation. DO NOT TRIGGER for local file deletion (use Bash), or for net-new deploys (use platform-metadata-deploy)."
allowed-tools:
  - Bash
  - Read
  - Write
  - Glob
  - Grep
---

# Handling Destructive Changes

Coordinate metadata deletion against a Salesforce org via the destructiveChanges manifest. Runs in three phases: scope → validate → execute, with stricter guardrails for production.

## Phase 1 — Scope the deletion

### Step 1a — Gather the components to remove

Ask the user (or infer from context) which components to delete. For each, capture:
- Metadata type (e.g. `CustomObject`, `CustomField`, `ApexClass`, `Flow`, `PermissionSet`)
- API name (e.g. `Project__c`, `Account.Status__c`, `MyController`)

### Step 1b — Local dependency scan (best-effort)

Before generating the manifest, scan the local project for references to each component. Use Grep over `force-app/`:

```bash
grep -rn "<componentApiName>" force-app/ --include='*.cls' --include='*.trigger' --include='*.xml' --include='*.js' --include='*.html'
```

If references are found:
- List them to the user
- Recommend either updating those references first OR removing them in the same destructive deploy
- Do NOT proceed silently — surface the dependency risk

### Step 1c — Generate `destructiveChanges.xml`

Write to `manifest/destructiveChangesPre.xml` (for pre-deploy deletion) or `manifest/destructiveChangesPost.xml` (for post-deploy deletion). Use the standard Salesforce metadata format:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>Project__c</members>
        <members>OldThing__c</members>
        <name>CustomObject</name>
    </types>
    <types>
        <members>Account.Status__c</members>
        <name>CustomField</name>
    </types>
    <version>62.0</version>
</Package>
```

Use the API version from `sfdx-project.json`'s `sourceApiVersion`.

Group components by metadata type (one `<types>` block per type). For namespaced fields, use `Object.Field` notation.

## Phase 2 — Validate

ALWAYS validate before executing a destructive deploy:

```bash
sf project deploy validate \
  --pre-destructive-changes manifest/destructiveChangesPre.xml \
  --manifest manifest/package.xml \
  --target-org <alias> \
  --test-level RunLocalTests \
  --json
```

(For post-destructive: use `--post-destructive-changes`.)

If `package.xml` doesn't exist, create an empty one alongside (deletion-only deploy needs a package descriptor):

```xml
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <version>62.0</version>
</Package>
```

If validation fails, surface errors and STOP. Common failure modes:
- "Cannot delete: referenced by Apex/Flow/Layout" → component still has references
- "Cannot delete: required for license" → managed-package or license dependency
- "Insufficient access" → user lacks delete permission

## Phase 3 — Execute

### Production path

Confirm whether the target is production before executing. The reliable check is the gate's classifier, which resolves the org the same way the deploy hook does (returns `production|sandbox|scratch|trial|unknown`):

```bash
"${CLAUDE_PLUGIN_ROOT}/scripts/sf-deploy-gate" bucket <alias>
```

`unknown` means the org type could not be confirmed (usually an incomplete org record). Say so plainly: the deploy gate still allows the deploy, auto-deploy on save stays off for that org, and re-authenticating with `sf org login web` usually restores the classification.

If the classifier returns `production`:
1. Display destructive confirmation banner (mirroring `platform-quick-deploy`)
2. List EVERY component that will be deleted
3. Require explicit "yes, delete from PRODUCTION" confirmation
4. Reject `--purge-on-delete` unless the user types it explicitly

The PreToolUse hook (`sf-deploy-gate destructive`) will already block bare destructive commands against prod — surface that denial to the user, do not work around it.

### Sandbox / Scratch path

```bash
sf project deploy start \
  --pre-destructive-changes manifest/destructiveChangesPre.xml \
  --manifest manifest/package.xml \
  --target-org <alias> \
  --json \
  --wait 30
```

Add `--purge-on-delete` only if the user explicitly asked to permanently delete (skip the recycle bin).

## Phase 4 — Post-delete cleanup

After a successful destructive deploy:
- Recommend a `sf project retrieve start --metadata <Type>:<Name>` is NOT useful (component is gone) — instead suggest cleaning up the local source:
  ```bash
  # Remove the now-deleted local files to keep source tracking accurate
  rm -rf force-app/main/default/<path-to-component>
  ```
- If deleting a custom field with data, remind the user that data is gone (or in the recycle bin until purged)
- Recommend running tests to confirm no runtime regressions

## Rules

- ALWAYS validate first; NEVER skip Phase 2
- ALWAYS scan for local references; NEVER delete blindly
- ALWAYS gate production with explicit user confirmation
- NEVER add `--purge-on-delete` without explicit user request
- NEVER use `--ignore-errors` on a destructive deploy
- ALWAYS use the API version from `sfdx-project.json`, not a hardcoded value
- If the user is deleting a field with `required="true"` or that's used in `RecordType` picklist values, surface the cascade impact before proceeding

© forcedotcom · Apache-2.0 · forcedotcom/sf-skills

Similar skills

All skills for DevOps and infrastructure →

From the same set181

platform-capability-search This skill tells you where you are in the Connect → Project → Build → Test → Deploy → Observe journey and finds a plugin for a task no installed skill covers. CX Codex +1 2,800installs experience-lwr-site-generate Builds and edits Salesforce Experience Cloud LWR sites through DigitalExperience metadata: pages, routes, themes, guest access. CX Codex +1 2,700installs dx-apexguru-scan Runs an ApexGuru SFAP Scan API performance audit on Salesforce Apex code to detect governor limit antipatterns and query bottlenecks. CX Codex +1 2,700installs platform-environment-validate The skill scans your local Salesforce environment, reports each tool's status and offers to install or update what is missing. CX Codex +1 2,700installs platform-quick-deploy Deploys validated metadata to a Salesforce Production org without re-running tests. Helpful when shipping validated packages directly to live environments. CX Codex +1 2,700installs dx-project-create Scaffolds a new Salesforce DX project from CLI templates, moves the active session into the project folder, and connects a default org. Useful when starting a new Salesforce app. CX Codex +1 2,600installs experience-ui-bundle-mfa-configure Sets up multi-factor authentication for Salesforce Experience Site users by deploying the right permission sets and checking the login flow. CX Codex +1 2,600installs experience-lwc-base-components-integrate Picks the right Lightning Base Component for a UI task and wires it into an LWC bundle without breaking SLDS. CX Codex +1 2,600installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor