Skip to content

Instantly share code, notes, and snippets.

@nithesh1992
Created June 18, 2019 16:45
Show Gist options
  • Save nithesh1992/41514821ce00d320a90ae914bc3df856 to your computer and use it in GitHub Desktop.
Save nithesh1992/41514821ce00d320a90ae914bc3df856 to your computer and use it in GitHub Desktop.
Find Users with Custom Permission in Apex
Set < Id > permissionSetIds = new Set < Id >();
List < User > userList = new List < User >();
for ( SetupEntityAccess access : [ SELECT ParentId FROM SetupEntityAccess
WHERE SetupEntityId IN ( SELECT Id
FROM CustomPermission
WHERE DeveloperName = 'Allow_Save_Offer_Owner_Edit' )
]){
permissionSetIds.add(access.ParentId);
}
System.debug(permissionSetIds);
userList = [ SELECT Username FROM User WHERE Id IN (
SELECT AssigneeId FROM PermissionSetAssignment
WHERE PermissionSetId IN :permissionSetIds) ];
System.debug(userList);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment