Apex permission set
Development
Kumaresan  

un assign the permission set with the help of the apex trigger for the user

Everyone aware permission sets provides the way to play with the salesforce access. using apex we can dynamically do the assign and unassign for the user.

Here’s an example of how you could unassign a permission set from a user using an Apex trigger:

trigger UnassignPermissionSet on User (before update) {
    List<PermissionSetAssignment> psaList = [SELECT Id, PermissionSetId, AssigneeId FROM PermissionSetAssignment WHERE AssigneeId = :Trigger.Old[0].Id];
    if (!psaList.isEmpty()) {
        delete psaList;
    }
}

In this trigger, we first retrieve a list of all the PermissionSetAssignment records that are associated with the user being updated in our salesforce org.

Let’s check If the list is not empty, meaning there are permission sets assigned to the user, then we delete the PermissionSetAssignment records, effectively unassigning the permission sets from the user. The trigger uses a before update trigger on the User object to catch the changes to the user and unassign the permission sets before the updates are committed to the database.

Leave A Comment