function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Seba Melgin2323Seba Melgin2323 

PermissionSetAssignment

Hi guys,
I'm trying to DELETE a PermissionSetAssignment on an Uninstall class (which implements UninstallHandler). Here is the code:
 
global void onUninstall(UninstallContext ctx) { unassignPermissionSet(ctx.uninstallerId()); }

/**
* @description
* deletes the assignment between current User and the permissionSet.
*/
public static void unassignPermissionSet(Id currentUserId) {
     PermissionSet[] ps = [SELECT Id FROM PermissionSet WHERE Name = :VOIQConstants.PERMISSION_SET_NAME];
     PermissionSet psVOIQPermSet;
     if (ps.size() > 0) {
         psVOIQPermSet = ps.get(0);

         // Assign the current User to Permission Set.
         if (PermissionSetAssignment.sObjectType.getDescribe().isDeletable()) {
             delete [SELECT Id FROM PermissionSetAssignment WHERE PermissionSetId = :psVOIQPermSet.Id];
         }
     }
 }
When I try to uninstall the package (which is a managed package) it throws an error:

Developer script exception (...). : Uninstall : DML operation DELETE not allowed on PermissionSetAssignment

Anyone can help us on it ? The PermissionSet is in the same package we trying to uninstall. Any suggestion to delete the permissionSetAssignment on another event than Uninstall ? (with the same purpose). Thanks !
SoundarSoundar
Hi Seba,

Take alook at Permissioner... free app that makes managing Permission Sets a breeze. Let me know if it helps.
https://appexchange.salesforce.com/listingDetail?listingId=a0N30000008XYMlEAO

"The Permissioner dramatically reduces the time involved with assigning and revoking permission sets assignments to multiple users. Using a simple interface, administrators can select one or more permission sets to assign to one or more users at a time"

Regards ,

Soundar.
Seba Melgin2323Seba Melgin2323
Hi Soundar,
I appreciate your comment and I will take a look to the app. But it doesn't solves my problem.
I want to delete the PermissionSetAssignment "before" uninstall the managed package, so I think I wrote the code on the wrong place ... but I don't know where to write it.
If I don't delete the PermissionSetAssignment, Salesforce cannot uninstall the package (the PermissionSet is an integral part of the managed package).