How to find the number of Permission Set assigned to an user in Salesforce?

How to find the number of Permission Set assigned to an user in Salesforce?

Sample Code:

Map<Id, List<PermissionSetAssignment>> mapUserIdPermAssignList = new Map<Id, List<PermissionSetAssignment>>();
List<PermissionSetAssignment> listPermAssign = [SELECT AssigneeId, PermissionSetId FROM PermissionSetAssignment];


for(PermissionSetAssignment PA : listPermAssign) {
if(!mapUserIdPermAssignList.containsKey()) {
mapUserIdPermAssignList.put(PA.AssigneeId, new List<PermissionSetAssignment>());
}
mapUserIdPermAssignList.get(PA.AssigneeId).add(PA);
}

here mapUserIdPermAssignList contains User Id and their related list of Permission Set.

Cheers!!!

Leave a Reply