Sub topic 12
A safe workflow: validate, review, and track deletions
This chapter assumes you can write a package.xml and a destructive changes file, and that you know the difference between pre and post destructive files. It puts those pieces into a repeatable process. A deletion is the one metadata change you can't always reverse, so the process checks it several times before it reaches production.
Why deletions need their own process
A normal deployment adds or updates components, and you can redeploy an older version if something breaks. A destructive deployment removes components. Anything that referenced them can break, and data stored in a deleted custom field may be hard to recover. The workflow below moves the risk to places where it is cheap: your repository, a sandbox, and a validation run.
Step 1: Find references before you delete
Most failed deletions come from a component that something else still uses. Search your source for the name before you write any XML.
grep -rn "LegacyAccountService" force-app/
grep -rn "OldRegion__c" force-app/Check Apex code, flows, page layouts, validation rules, reports, and permission sets. Matches in files that you aren't deleting are the dependencies you must fix first. Also look at the org itself. Components created directly in the org, such as reports, may not appear in your project.
Step 2: Keep the deletion in version control
Put the destructive changes files in the repository, for example in manifest/. Open a pull request for them like any other change. Reviewers can then read the exact list of members and check that each name is spelled correctly. A wrong name usually produces a warning or an error rather than a deletion, so review the names against the source.
Use a clear commit message that names the components and the reason for removing them. The commit history then records what was deleted, when, and by whom. That is hard to reconstruct from the org alone.
Step 3: Validate in a sandbox first
Run the deployment with --dry-run. This checks the deployment, including the destructive changes, without saving anything to the org.
sf project deploy start \
--manifest manifest/package.xml \
--post-destructive-changes manifest/destructiveChangesPost.xml \
--dry-run \
--target-org my-sandboxRead the failure messages carefully. A message about a dependency names the component that still uses your target. Fix that component, then validate again. When the validation passes, run the same command without --dry-run to deploy to the sandbox. Then check the result by hand: open the app, run the affected flows, and confirm that reports still work.
Step 4: Validate against production, then deploy
A sandbox may not match production. Production can have extra reports, layouts, or integrations that reference the component. Validate against production before the real deployment. Production deployments that include Apex need tests, so set a test level.
sf project deploy start \
--manifest manifest/package.xml \
--post-destructive-changes manifest/destructiveChangesPost.xml \
--test-level RunLocalTests \
--dry-run \
--target-org my-productionWhen the validation succeeds, deploy during a planned window. Use the same files and the same options as in the validation, without --dry-run. Never edit the destructive file between validation and deployment.
Step 5: Remove the component from source
A destructive deployment deletes components from the org only. Your local project still holds the files. If you leave them, the next full deployment recreates the component you just deleted. After the production deployment succeeds, remove the files from force-app/ in the same pull request or a follow-up one. Then clear the processed entries out of the destructive changes file, or archive it, so nobody redeploys it by accident.
For a single component, sf project delete source removes it from both the org and your local source in one step. Use it for quick cleanup in a sandbox. For production, the manifest-based process above gives you a reviewable record.
Checklist
| Stage | Question to answer |
|---|---|
| Before writing | Does anything still reference this component? |
| Review | Are the member names exact and in the correct file (pre or post)? |
| Sandbox validation | Does the dry run pass, and does the app still work after a real deploy? |
| Production validation | Does the dry run pass with tests? |
| Cleanup | Are the local source files and the used destructive entries removed? |
Exercise
You deleted Account.OldRegion__c from production with a post destructive changes file. A week later, a teammate deploys the whole force-app directory from their branch, and the field reappears. What step was missed, and how do you prevent it?
Show answer
The local source files for the field were never removed from the project. A deployment of force-app recreates anything it contains. After a successful production deletion, remove the field's source files (or use sf project delete source in a sandbox), commit that change, and clear or archive the used destructive changes file.
Exercise
Why do you validate with --dry-run against production even after the same deployment passed in a sandbox?
Show answer
Production can contain components, such as extra layouts, reports, or integrations, that reference the target and don't exist in the sandbox. Production also requires tests for Apex deployments. A dry run exposes these dependency and test failures without changing the org.