I've like to automate the process of removing users from a Permission Set when uninstalling a managed package:

global class AppUninstallHandler implements UninstallHandler {

    global void onUninstall(UninstallContext ctx) {

        List<String> names = new List<String> {'Power_User', 'Normal_User'};

        Set<Id> ids = (new Map<Id, PermissionSet>([SELECT ID FROM PermissionSet WHERE Name IN : names])).keySet();

        List<PermissionSetAssignment> assigments = [SELECT ID FROM PermissionSetAssignment WHERE PermissionSetId IN :ids];

        delete assigments;

But I still get the error message asking me to manually remove them before I can uninstall.

I am guessing the UninstallHandler cannot run unit after I've removed the users already?

1 Answer 1


Correct. The uninstall handler won't run until the uninstall is successful. You could create a page/component/whatever to automate the removal of the permission sets, you just can't use this specific interface to do so.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .