Agent Skillsforcedotcom/sf-skills › platform-destructive-deploy

platform-destructive-deploy

GitHub

在Salesforce组织中执行破坏性变更部署,用于删除自定义对象、字段等元数据。包含范围界定、本地依赖扫描、验证及生产环境确认流程,确保删除操作安全合规。

plugins/builder/salesforce-development/skills/platform-destructive-deploy/SKILL.md forcedotcom/sf-skills

Trigger Scenarios

用户请求从组织删除自定义对象或字段 执行破坏性部署以移除元数据组件

Install

npx skills add forcedotcom/sf-skills --skill platform-destructive-deploy -g -y
More Options

Non-standard path

npx skills add https://github.com/forcedotcom/sf-skills/tree/main/plugins/builder/salesforce-development/skills/platform-destructive-deploy -g -y

Use without installing

npx skills use forcedotcom/sf-skills@platform-destructive-deploy

指定 Agent (Claude Code)

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

安装 repo 全部 skill

npx skills add forcedotcom/sf-skills --all -g -y

预览 repo 内 skill

npx skills add forcedotcom/sf-skills --list

SKILL.md

Frontmatter
{
    "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/:

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

Version History

  • 1.33.0 Current 2026-08-05 13:01

Same Skill Collection

plugins/builder/salesforce-development/skills/automation-flow-generate/SKILL.md
plugins/builder/salesforce-development/skills/platform-apex-logs-debug/SKILL.md
plugins/builder/salesforce-development/skills/platform-capability-search/SKILL.md
plugins/builder/salesforce-development/skills/platform-custom-application-generate/SKILL.md
plugins/builder/salesforce-development/skills/platform-custom-tab-generate/SKILL.md
plugins/builder/salesforce-development/skills/platform-deploy-validate/SKILL.md
plugins/builder/salesforce-development/skills/platform-lightning-app-coordinate/SKILL.md
plugins/builder/salesforce-development/skills/platform-list-view-generate/SKILL.md
plugins/builder/salesforce-development/skills/platform-metadata-deploy/SKILL.md
plugins/builder/salesforce-development/skills/platform-permission-set-generate/SKILL.md
plugins/builder/salesforce-development/skills/platform-quick-deploy/SKILL.md
plugins/builder/salesforce-development/skills/platform-validation-rule-generate/SKILL.md
skills/automation-flow-generate/SKILL.md
skills/commerce-b2b-open-code-components-integrate/SKILL.md
skills/commerce-b2b-store-create/SKILL.md
skills/data360-activate/SKILL.md
skills/data360-code-extension-generate/SKILL.md
skills/data360-prepare/SKILL.md
skills/data360-schema-get/SKILL.md
skills/design-systems-slds-apply/SKILL.md
skills/dx-org-permission-set-assign/SKILL.md
skills/dx-org-switch/SKILL.md
skills/experience-lwc-generate/SKILL.md
skills/experience-ui-bundle-file-upload-generate/SKILL.md
skills/experience-ui-bundle-site-generate/SKILL.md
skills/external-diagram-mermaid-generate/SKILL.md
skills/external-diagram-visual-generate/SKILL.md
skills/platform-apex-logs-debug/SKILL.md
skills/platform-custom-application-generate/SKILL.md
skills/platform-custom-lightning-type-generate/SKILL.md
skills/platform-custom-tab-generate/SKILL.md
skills/platform-lightning-app-coordinate/SKILL.md
skills/platform-list-view-generate/SKILL.md
skills/platform-metadata-deploy/SKILL.md
skills/platform-permission-set-generate/SKILL.md
skills/platform-validation-rule-generate/SKILL.md
plugins/builder/salesforce-development/skills/agentforce-generate/SKILL.md
plugins/builder/salesforce-development/skills/agentforce-observe/SKILL.md
plugins/builder/salesforce-development/skills/agentforce-test/SKILL.md
plugins/builder/salesforce-development/skills/dx-code-analyzer-configure/SKILL.md
plugins/builder/salesforce-development/skills/dx-code-analyzer-custom-rule-create/SKILL.md
plugins/builder/salesforce-development/skills/dx-code-analyzer-run/SKILL.md
plugins/builder/salesforce-development/skills/dx-org-manage/SKILL.md
plugins/builder/salesforce-development/skills/dx-project-create/SKILL.md
plugins/builder/salesforce-development/skills/platform-apex-anonymous-run/SKILL.md
plugins/builder/salesforce-development/skills/platform-apex-generate/SKILL.md
plugins/builder/salesforce-development/skills/platform-apex-test-generate/SKILL.md
plugins/builder/salesforce-development/skills/platform-apex-test-run/SKILL.md
plugins/builder/salesforce-development/skills/platform-architecture-analyze/SKILL.md

Metadata

Files
0
Version
1.33.0
Hash
75961d47
Indexed
2026-08-05 13:01

- 위키
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-06 01:24
浙ICP备14020137号-1 $방문자$