Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

How Does an Uninstall Script Work?

An uninstall script is an Apex class that implements the UninstallHandler interface. This interface has a single method called onUninstall that specifies the actions to be performed on uninstall.
1global interface UninstallHandler {
2  void onUninstall(UninstallContext context)
3}
The onUninstall method takes a context object as its argument, which provides the following information.
  • The org ID of the organization in which the uninstall takes place.
  • The user ID of the user who initiated the uninstall.
The context argument is an object whose type is the UninstallContext interface. This interface is automatically implemented by the system. The following definition of the UninstallContext interface shows the methods you can call on the context argument.
1global interface UninstallContext { 
2  ID organizationId();
3  ID uninstallerId();
4}