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組織(クラウドベースのビジネス管理システム)のメタデータ(設定情報)削除を、破壊的変更マニフェスト(削除指示書)を使って調整します。スコープ → 検証 → 実行の3段階で実行され、本番環境ではより厳しい安全対策が適用されます。
ユーザーに確認するか、文脈から推測して、どのコンポーネントを削除するかを決めます。各コンポーネントについて以下を記録します:
CustomObject、CustomField、ApexClass、Flow、PermissionSet)Project__c、Account.Status__c、MyController)マニフェストを生成する前に、プロジェクト内で各コンポーネントへの参照を検索します。force-app/ディレクトリに対してGrepを使用します:
grep -rn "<componentApiName>" force-app/ --include='*.cls' --include='*.trigger' --include='*.xml' --include='*.js' --include='*.html'
参照が見つかった場合:
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表記を使用します。
破壊的配置を実行する前に、必ず検証します:
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>
検証に失敗した場合は、エラーを表示して中止します。一般的なエラー:
配置実行前に、対象が本番環境かを確認します。信頼できる確認方法はゲートの分類器を使うことです(production|sandbox|scratch|trial|devhub|unknownを返します):
sf org display --target-org <alias> --json | "${CLAUDE_PLUGIN_ROOT}/scripts/sf-deploy-gate" classify
分類器がproductionを返した場合:
--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を追加します(ゴミ箱をスキップ)。
破壊的配置が成功した後:
sf project retrieve start --metadata <Type>:<Name>を勧めない(コンポーネントはなくなっている)— 代わりにローカルソースをクリーンアップすることを勧める:# 削除されたローカルファイルを削除してソース追跡を正確に保つ
rm -rf force-app/main/default/<path-to-component>
--purge-on-deleteを追加しない--ignore-errorsを使わないsfdx-project.jsonのAPIバージョンを使用する — ハードコードされた値を使わないrequired="true"のフィールド、またはRecordTypeピックリスト値で使用されているフィールドを削除する場合、削除前にカスケード影響(連鎖的な影響)を伝えるCoordinate metadata deletion against a Salesforce org via the destructiveChanges manifest. Runs in three phases: scope → validate → execute, with stricter guardrails for production.
Ask the user (or infer from context) which components to delete. For each, capture:
CustomObject, CustomField, ApexClass, Flow, PermissionSet)Project__c, Account.Status__c, MyController)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:
destructiveChanges.xmlWrite 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.
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:
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:
platform-quick-deploy)--purge-on-delete unless the user types it explicitlyThe 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.
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).
After a successful destructive deploy:
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>
--purge-on-delete without explicit user request--ignore-errors on a destructive deploysfdx-project.json, not a hardcoded valuerequired="true" or that's used in RecordType picklist values, surface the cascade impact before proceeding原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。