Sub topic 12
Uninstalling an app and planning a rollback
This chapter assumes you can work in Setup and know how sandboxes differ from production. It also assumes you have installed a package before, using the earlier chapters of this tutorial. Uninstalling is the last safety control. You should rehearse it before you rely on it.
What uninstalling does
When you uninstall a managed package, Salesforce removes the package's components from the org. These include its custom objects, fields, Apex classes, flows, and permission sets. Data stored in the package's custom objects is deleted with them. Salesforce lets you export a copy of that data during uninstall, and you should always take it.
Uninstalling does not restore your org to the state before the install. Anything you built on top of the package is affected. That includes reports, flows, page layouts, and Apex that reference package components.
Managed and unmanaged packages differ
A managed package is uninstalled as one unit. An unmanaged package has no single uninstall action, because its components become ordinary parts of your org after install. To remove one, you delete each component yourself and check the dependencies for each. This is a main reason to prefer managed packages when you have a choice.
Plan the rollback before you install
Write the rollback plan before production work starts. It should answer these questions:
- What data will users create in the app, and how will you export it?
- Which of your own components depend on the package?
- Who approves the uninstall, and in what time window will it run?
- If the app was installed to replace another tool, how do you bring that tool back?
You cannot downgrade a managed package in place to an earlier version. If an upgrade causes problems, the usual path is to uninstall and reinstall the earlier version, which means package data is lost. Take a data export before every upgrade, and test the upgrade in a sandbox first.
Find dependencies first
The most common uninstall failure is a dependency error. Salesforce blocks the uninstall if something outside the package still uses a package component. Typical causes are:
- A custom field on a standard object, such as Account, that the package added and a report or formula still references.
- A flow or Apex class that calls a package class.
- A page layout or Lightning page that includes a package component.
- A validation rule or formula field that uses a package field.
In Setup, open Installed Packages and review the package's components. Use the Where is this used? option on individual components where it is available. Fix the references before you try the uninstall, not after the error appears.
Rehearse in the sandbox
Run the uninstall in the sandbox where you tested the app. The command below removes the package and waits up to 10 minutes. Replace the placeholder 04t ID with the one from your install.
sf package uninstall --package 04tXXXXXXXXXXXXXXX --target-org my-sandbox --wait 10Then confirm the package is gone:
sf package installed list --target-org my-sandboxIf the package no longer appears in the list, the uninstall worked. Check what else changed. Open the reports and dashboards that used the app, run the flows that touched its objects, and ask a test user to sign in. Record every error. Each one is a task for the production plan.
Run it in production
Schedule the uninstall for a low-traffic window and tell users in advance. Follow the order you rehearsed:
- Export the package data and store it where the business owner can reach it.
- Remove or rework the dependent components.
- Uninstall the package, with the same command and options you used in the sandbox.
- Verify reports, flows, page layouts, and user access.
- Close the loop: tell users the app is gone and update your governance records.
Do not leave package permission sets assigned to users as a shortcut. They are removed with the package, so check that users still have the access they need for any replacement tool.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Uninstall fails with a dependency message | A report, flow, or field still references a package component | Remove or edit the reference, then retry |
| Users lose access to a feature unexpectedly | Package permission sets were removed | Assign equivalent access from your own permission sets |
| Records are missing after uninstall | Package object data was deleted | Restore from the export you took |
| Reinstall does not bring back old data | Reinstalling starts clean | Reload the exported data |
Exercise
Your team upgrades a managed package in production, and the new version breaks a key process. You have no export of the package data. Why is rollback risky, and what should you have done before the upgrade?
Show answer
Managed packages cannot be downgraded in place, so the usual rollback is to uninstall and reinstall the earlier version. Uninstalling deletes the data in the package's custom objects, so without an export that data is lost. Before the upgrade you should have tested it in a sandbox, exported the package data, and written down the rollback steps.
Exercise
An uninstall in your sandbox fails because a report references a field added by the package. What do you do next, and why is this useful before production?
Show answer
Edit or remove the report so it no longer uses the package field, then retry the uninstall. Finding this in the sandbox shows which dependencies you must clear in production, so the production uninstall does not fail partway through the maintenance window.