通过指定用户ID获取其CustomPermission的办法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
public with sharing class getCustomPermissionByUserId { public static void execute(Id UserId){ list<SetupEntityAccess> SetupEntityAccesslist = [SELECT Id , ParentId, Parent.name, SetupEntityId FROM SetupEntityAccess WHERE SetupEntityType = 'CustomPermission']; list<id> SetupEntityAccessParentIds = new list<id> (); for(SetupEntityAccess item : SetupEntityAccesslist){ SetupEntityAccessParentIds.add(item.ParentId); } list<PermissionSetAssignment> PermissionSetAssignmentlist = [SELECT PermissionSet.Id,Assignee.Name, PermissionSet.Profile.Name, PermissionSet.isOwnedByProfile, PermissionSet.Label FROM PermissionSetAssignment WHERE PermissionSetId IN :SetupEntityAccessParentIds and Assignee.Id = :UserId]; list<CustomPermission> CustomPermissionlist = [SELECT Id, IsDeleted, DeveloperName, Language, MasterLabel FROM CustomPermission]; map<id , CustomPermission> CustomPermissionMap = new map<id , CustomPermission>(); for(CustomPermission item : CustomPermissionlist){ CustomPermissionMap.put(item.Id, item); } user myuser = [select id , name from user where id =:UserId]; System.debug('ユーザID : '+myuser.Name);// 人名 for(SetupEntityAccess item : SetupEntityAccesslist){ for(PermissionSetAssignment subitem : PermissionSetAssignmentlist){ if(subitem.PermissionSetId == item.ParentId){ CustomPermission myCustomPermission = CustomPermissionMap.get(item.SetupEntityId); System.debug('カスタム権限 : '+myCustomPermission.DeveloperName);// カスタム権限名 System.debug('→プロファイル付与 : '+subitem.PermissionSet.isOwnedByProfile);// プロファイル付与 System.debug('→権限セットId : '+subitem.PermissionSet.Id);// 権限セットId System.debug('→プロファイル名 : '+subitem.PermissionSet.Profile.Name);// プロファイル名 } } } } } |