• Projects
  • Service
  • About
  • branding.bz
  • Podcast
  • Tips
  • FAQ
  • Recruit
  • Download
  • Contact
  • branding.bz(ブランド構築SaaS)
  • DESIGN NOW(デザインメディア)
  • X
  • LinkedIn
  • Spotify
  • Facebook

213-0011 神奈川県川崎市高津区久本3-6-7-303

© 2026 ID INC. All rights reserved

claude-skills/スキル
SKILLOfficialdevelopment

platform-destructive-deploy

プラグイン
salesforce-development
ソース
GitHub で見る ↗
説明

Salesforce(CRM・顧客管理システム)の組織に対して、destructiveChanges.xml(削除指示リスト)による削除・デプロイワークフロー(デプロイ:システムへの配置)を実行します。 **次のような場合に使用:** - ユーザーがカスタムオブジェクト、フィールド、Apexクラス、フロー、またはその他のメタデータコンポーネント(システム構成情報)を組織から削除・削除したいと要望する場合 - リリース(公開)の一部として「破壊的デプロイ」(既存のコンポーネント削除を伴うデプロイ)や削除を実行する場合 実行前にバリデーション(検証)を行い、本番環境への作用を明示的な確認で制限します。 **使用しない場合:** - ローカルファイルの削除(Bashを使用) - 新規コンポーネントのデプロイ(platform-metadata-deployを使用)

原文を表示

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).

ユースケース
  • Salesforceから不要なメタデータを削除するとき
  • 破壊的デプロイを実行するとき
  • リリースの一部として削除作業を行うとき
  • 削除実行前に検証を行いたいとき
本文(日本語訳)

破壊的変更の処理

Salesforce組織(クラウドベースのビジネス管理システム)のメタデータ(設定情報)削除を、破壊的変更マニフェスト(削除指示書)を使って調整します。スコープ → 検証 → 実行の3段階で実行され、本番環境ではより厳しい安全対策が適用されます。

段階1 — 削除の範囲を決める

ステップ1a — 削除するコンポーネント(部品)を確認する

ユーザーに確認するか、文脈から推測して、どのコンポーネントを削除するかを決めます。各コンポーネントについて以下を記録します:

  • メタデータタイプ(例:CustomObject、CustomField、ApexClass、Flow、PermissionSet)
  • API名(例:Project__c、Account.Status__c、MyController)

ステップ1b — ローカル依存関係スキャン(ベストエフォート)

マニフェストを生成する前に、プロジェクト内で各コンポーネントへの参照を検索します。force-app/ディレクトリに対してGrepを使用します:

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

参照が見つかった場合:

  • ユーザーに一覧を表示する
  • その参照をまず更新するか、同じ破壊的配置(削除作業)で一緒に削除することを勧める
  • 黙って進めない — 依存関係リスク(削除が他の部分に影響する可能性)を必ず伝える

ステップ1c — destructiveChanges.xml を生成する

manifest/destructiveChangesPre.xml(配置前に削除)またはmanifest/destructiveChangesPost.xml(配置後に削除)に書き込みます。Salesforceの標準メタデータ形式を使用します:

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

sfdx-project.jsonのsourceApiVersionからAPIバージョンを使用します。

メタデータタイプごとにコンポーネントをまとめます(タイプごとに1つの<types>ブロック)。名前空間付きフィールドの場合はObject.Field表記を使用します。

段階2 — 検証

破壊的配置を実行する前に、必ず検証します:

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

(配置後削除の場合は--post-destructive-changesを使用します。)

package.xmlが存在しない場合は、空のファイルを作成します(削除のみの配置にはパッケージ記述ファイルが必要):

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

検証に失敗した場合は、エラーを表示して中止します。一般的なエラー:

  • 「削除不可:Apex/Flow/レイアウトから参照されている」 → コンポーネントがまだ他の部分から使用されている
  • 「削除不可:ライセンスに必須」 → 管理パッケージまたはライセンス依存関係
  • 「アクセス不足」 → ユーザーに削除権限がない

段階3 — 実行

本番環境のパス

配置実行前に、対象が本番環境かを確認します。信頼できる確認方法はゲートの分類器を使うことです(production|sandbox|scratch|trial|devhub|unknownを返します):

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

分類器がproductionを返した場合:

  1. 破壊的変更確認バナー(「platform-quick-deploy」に倣った表示)を表示
  2. 削除されるすべてのコンポーネントをリストアップ
  3. 「はい、本番環境から削除します」という明示的な確認を要求
  4. ユーザーが明示的に入力しない限り--purge-on-delete(ゴミ箱をスキップして完全削除)を拒否

PreToolUseフック(sf-deploy-gate destructive)は既に本番環境に対する単なる破壊的コマンドをブロック — その拒否をユーザーに伝え、回避しないでください。

サンドボックス・スクラッチ環境のパス

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

ユーザーが明示的に完全削除を要求した場合のみ--purge-on-deleteを追加します(ゴミ箱をスキップ)。

段階4 — 削除後のクリーンアップ

破壊的配置が成功した後:

  • sf project retrieve start --metadata <Type>:<Name>を勧めない(コンポーネントはなくなっている)— 代わりにローカルソースをクリーンアップすることを勧める:
    # 削除されたローカルファイルを削除してソース追跡を正確に保つ
    rm -rf force-app/main/default/<path-to-component>
    
  • カスタムフィールドを削除し、そのフィールドにデータが含まれていた場合、データは失われた(またはゴミ箱に残っている)ことを思い出させる
  • テストを実行して実行時の問題がないか確認することを勧める

ルール

  • 必ず検証する — 段階2をスキップしない
  • 必ずローカル参照をスキャンする — 盲目的に削除しない
  • 必ず本番環境をユーザーの明示的確認でゲート — 許可なく実行しない
  • ユーザーの明示的な要求なしに--purge-on-deleteを追加しない
  • 破壊的配置で--ignore-errorsを使わない
  • sfdx-project.jsonのAPIバージョンを使用する — ハードコードされた値を使わない
  • ユーザーがrequired="true"のフィールド、またはRecordTypeピックリスト値で使用されているフィールドを削除する場合、削除前にカスケード影響(連鎖的な影響)を伝える
原文(English)を表示

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

原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。