Sub topic 12
Uninstalling an app and planning a rollback
This chapter assumes you can work in Setup, know how profiles and permission sets assign access, and understand the difference between a sandbox and production. It also assumes you have already trialed the app in a sandbox, as covered in earlier chapters. Here you learn what an uninstall removes, what blocks it, and how to plan a way back before you install in production.
Why plan the exit before the install
Installing an app is easy to undo only if you prepared for it. Once users have created records, built flows that reference the app's fields, or added the app's components to page layouts, removing it changes things your org now depends on.
Salesforce does not offer a "revert to the state before install" button for production. Your rollback is whatever you prepared: a sandbox rehearsal, a metadata backup, a data export, and a written sequence of steps. This chapter covers each of those.
What an uninstall removes
Uninstalling a package deletes the components it owns. Typical examples:
- Custom objects the package created, and every record in them.
- Custom fields the package added to your own objects, standard or custom, and the data in those fields.
- Apex classes, triggers, Lightning components, flows, and page layouts that belong to the package.
- Permission sets and tabs that the package defined.
Your own customizations are not removed, but they can break. A report that groups by a package field loses that column. A flow that updates a package object stops working. A formula field that references a package field blocks the uninstall until you change it.
| Item | What happens on uninstall |
|---|---|
| Package custom objects and their records | Deleted. A copy of the data can be exported (see below). |
| Package fields on your objects | Deleted, along with the values stored in them. |
| Your fields, flows, and Apex that reference package components | Block the uninstall until you remove the references. |
| Users' permission set assignments for package permission sets | Removed along with the permission sets. |
| Callouts and scheduled jobs created by the package | Stop. Check Scheduled Jobs for leftovers. |
| Records in your own objects (Accounts, Contacts) | Kept. |
Managed and unmanaged packages behave differently
The distinction from the package types chapter matters again here.
A managed package is uninstalled as a single unit. Salesforce knows which components belong to it, so one action removes all of them.
An unmanaged package is different. Its components were copied into your org as ordinary metadata, and Salesforce does not track them as a unit. You generally remove them one at a time: each object, field, class, and layout. Before you start, build a list of what the package added. The install confirmation, the package's documentation, and a comparison of your org's metadata before and after a sandbox install are the usual sources.
If you rehearsed the install in a sandbox, you already have this list. That is one more reason to install in a sandbox first.
Preparing for the uninstall
Work through these steps in the sandbox first. Then repeat them in production, with a change window if your organization uses one.
- Find dependencies. Look for anything of yours that references the package. Common places are flows, validation rules, formula fields, Apex, reports, list views, page layouts, and email templates. Use the "Where is this used?" button on a package field and search Setup for the package's namespace prefix.
- Remove or rewrite those references. Deactivate the flows that call package actions. Remove package fields from layouts and reports. Rewrite Apex that uses package classes.
- Remove access. Take away the package's permission sets from users. This is not strictly required, but it lets you see who is affected and stops new data from entering the app while you work.
- Stop inbound traffic. Disable integrations, connected apps, and scheduled jobs that send data to the package.
- Export what you need. Decide what data you must keep, then export it (see the next section).
- Tell the users. Say what is going away and when, so nobody enters data in the app after your backup.
Keeping the data
Data in package objects and fields is deleted with the package. You have two layers of protection, and you should use both.
During the uninstall in Setup, you can choose to export a copy of the package's data. Salesforce emails you a link to the export when it is ready. The export is a file of CSVs, which is useful for reference but not a restore mechanism by itself.
Salesforce also keeps the uninstalled package and its data for a limited time, listed under Deleted Packages in Setup. During that period you can reinstall the package and recover the data. The retention period is set by Salesforce and has been documented as 15 days. Confirm the current figure in the Salesforce help before you rely on it.
Do not treat those two safety nets as your backup plan. Take your own export first, using Data Export, Data Loader, or your backup tool, covering the package objects and the package fields on your own objects.
Uninstalling in Setup
- Go to Setup, search for Installed Packages, and find the package.
- Click Uninstall next to it.
- Choose whether to save a copy of the package's data. Select the export option unless you have already confirmed you do not need the data.
- Confirm that you understand the data will be deleted, and click Uninstall.
- Wait for the confirmation email. Large packages can take a while, and Salesforce may report the result by email rather than on the screen.
If the uninstall fails, the message lists the components that are in use and what references them. Remove the references and try again.
Uninstalling with the CLI
The Salesforce CLI can run the same operation, which is useful for rehearsals you want to repeat. The command targets second-generation packages. For other packages, use Setup.
sf package uninstall --package 04tXXXXXXXXXXXXXXX --target-org my-sandbox --wait 10Replace the placeholder with the 04t package version ID. The --wait 10 option waits up to 10 minutes for the job. If the job runs longer, the command returns a request ID that begins with 06y. You can check on it later:
sf package uninstall report --request-id 06yXXXXXXXXXXXXXXX --target-org my-sandboxAfterward, confirm the package is gone:
sf package installed list --target-org my-sandboxIf the package no longer appears in the list, the uninstall finished. Then check the things the list cannot show you: run your key processes, open the main page layouts, and check for new errors in flows and Apex.
Common reasons an uninstall fails
- A custom field of yours references a package field. This includes formula fields, roll-up summaries, and validation rules. Edit or delete the field first.
- A flow or process references a package object or action. Deactivate it, and in some cases delete old versions too. Inactive versions can still hold references.
- Another installed package depends on this one. Uninstall the dependent package first, or find out whether you still need it.
- Active scheduled Apex or batch jobs from the package. Wait for them to finish or abort them in Scheduled Jobs.
- Apex test or code coverage conflicts. Apex of yours that calls package code must be rewritten before the package can go.
- Package components appear in a deployed change set or are in use in a reference. Remove those references from your deployment sources as well, or the next deployment will re-add references to missing components.
Rollback planning beyond uninstall
An uninstall is one kind of rollback. Others you may need:
- Rolling back an upgrade. Salesforce does not let you downgrade a managed package to an earlier version. If an upgrade causes trouble, your options are to fix forward with the publisher's help, restore from a sandbox that still has the earlier version, or uninstall and reinstall the earlier version, with its data loss implications. Test every upgrade in a sandbox first, as covered in the licensing and updates chapter.
- Rolling back an install that went wrong. If you installed for admins only, as the install options chapter recommends, the damage is limited to what admins did. Uninstall, then review the audit trail for what changed.
- Rolling back access. Removing a permission set assignment is instant and reversible. If you only need to stop use of an app quickly, remove access first and uninstall later.
A rollback plan you can write down
Before the production install, put a short document in your change record. It should answer these questions:
- What is the trigger for rolling back, and who decides?
- Which access can be removed immediately, and which permission sets does that involve?
- Which objects and fields would need exporting, and where are the backups stored?
- What references to the package will exist in production after go-live, so you know what to clean up?
- Which version of the package is installed, and which version did you test in the sandbox?
- Who tests after the rollback, and which processes do they check?
The sandbox rehearsal fills in most of these answers. Run the uninstall there with the same steps you wrote down, and fix the plan wherever it was wrong.
Rehearsing the full cycle in a sandbox
A complete rehearsal takes less than an hour for most apps and finds problems that would otherwise appear in production.
- Install the package in a sandbox with the admins-only option.
- Assign one permission set to a test user:
sf org assign permset --name Example_App_User --target-org my-sandbox --on-behalf-of [email protected]- Create some test records. Add the app's fields to a layout and reference them from a test flow.
- Try to uninstall. Note which errors appear and what they reference.
- Remove the references, export the data, and uninstall.
- Run your regression checks, then compare the result with what you expected.
After the uninstall
- Check Setup for leftovers: scheduled jobs, remote site settings, named credentials, and connected apps that the app used. Some may remain and should be removed if no longer needed.
- Revoke any API tokens or integration users that were created for the app, and tell the publisher to delete your data from their systems if the app stored it externally. An uninstall does not delete data held on the publisher's servers.
- Update your internal inventory of installed apps and note the date and reason for removal.
- Look at the Deleted Packages list, and decide whether to let the retention window expire or reinstall.
Exercise
An admin uninstalls a managed package from production. The uninstall fails with a message that a formula field on Opportunity references a package field. List the steps to resolve this safely, and say what you should do before editing the formula field.
Show answer
First export the Opportunity data, including the formula field's inputs and the package field values, so nothing is lost. Then change the formula field so it no longer references the package field, or delete it if it is no longer needed, and check reports and flows that use that formula field. Rerun the uninstall, using the data export option. Afterward, verify with the installed package list and by running the affected processes. Rehearse the same steps in a sandbox first.
Exercise
Why is removing a user's permission set assignment not the same as uninstalling the app, and when would you do it first?
Show answer
Removing the assignment only stops that user from using the app. The package, its data, and its references in your org remain. Do it first when you need to stop use quickly, to see who is affected, or to block new data from entering the app while you prepare the export and clean up references, since the assignment can be restored if you change your mind.
Exercise
A managed package upgrade in production breaks a flow. Can you roll back to the previous package version? What options remain?
Show answer
No. Salesforce does not support downgrading a managed package. You can fix forward by working with the publisher or by editing your own flow, restore the earlier setup from a sandbox that still holds the previous version, or uninstall and reinstall the earlier version, accepting the data deletion unless you have exports. This is why upgrades should be tested in a sandbox first.