New to Claude Skills? Learn how to install them →

Dforcedotcom on GitHub

Destructive Deploy for Salesforce

OfficialFree

Safely manage metadata deletions in Salesforce.

Get this skill

Free · Opens the source repo

What Destructive Deploy for Salesforce does

The Destructive Deploy skill enables developers to execute a controlled deletion of metadata components within a Salesforce organization. It specifically targets the removal of custom objects, fields, Apex classes, flows, and other metadata elements, ensuring that the process is both safe and efficient. This skill operates in a structured workflow that consists of three main phases: scoping, validating, and executing the deletion.

In the first phase, the skill gathers the components that the user intends to delete, identifying their metadata types and API names. It performs a local dependency scan to check for any references to these components within the project files, alerting the user to potential issues before proceeding. This proactive approach helps prevent accidental deletions that could disrupt the functionality of the Salesforce org.

The validation phase is crucial; it ensures that all deletions are permissible before any changes are made. The skill validates the deletion against the Salesforce org, checking for errors such as dependencies that would prevent deletion or insufficient permissions. Only after successful validation does the skill move to the execution phase, where it requires explicit confirmation from the user if the target org is production, thereby adding an extra layer of security.

This skill is ideal for Salesforce developers and administrators who need a reliable method to manage metadata deletions while minimizing risks. It is particularly useful during release cycles when components need to be removed in a controlled manner, ensuring that all dependencies and impacts are considered before executing potentially destructive changes.

When to use it

Use this skill when you need to perform a destructive deploy of metadata components in Salesforce, especially in production environments.

When not to use it

Do not use this skill for local file deletions or for new deployments; it is specifically designed for deletions only.

What you can build with it

Deleting a Custom Object

When a custom object is no longer needed, use this skill to safely remove it from your Salesforce org, ensuring no dependencies are overlooked.

Removing Unused Fields

If you need to clean up your Salesforce schema by deleting unused custom fields, this skill helps manage the process safely.

Cleaning Up Apex Classes

When refactoring your codebase, use this skill to remove obsolete Apex classes, ensuring that all references are handled appropriately.

How to install Destructive Deploy for Salesforce

View source

1. Install with the skills CLI

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

2. Or install it manually

Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.

Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs

Inside SKILL.md

Written by forcedotcom

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/:

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 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:

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 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 (returns production|sandbox|scratch|trial|devhub|unknown):

sf org display --target-org <alias> --json | "${CLAUDE_PLUGIN_ROOT}/scripts/sf-deploy-gate" classify

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

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:
    # 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

Frequently asked questions about Destructive Deploy for Salesforce

Similar skills