npx skills add ...
npx skills add forcedotcom/sf-skills --skill platform-destructive-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).
npx skills add forcedotcom/sf-skills --skill platform-destructive-deploy
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/:
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:
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:
(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):
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):
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.
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:
--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