5

I'm trying to figure out how to query all users who have Author Apex permission (or any other system permissions). I thought it would be straightforward, but I don't see where it would be stored. With ObjectPermissions I can see which objects can be accessed, and with SetupEntityAccess I can see which setup entities can be accessed. Looking at the SetupEntityType picklist, the available types of setup entity are:

  • ApexClass
  • ApexPage
  • ConnectedApplication
  • ConnectedApplication
  • CustomPermission
  • ExternalDataSource
  • ExternalSocialAccount
  • NamedCredential
  • TabSet

None of these types seem to help either. Maybe I'm just forgetting something obvious, but I can't think of how I would query for system permissions. Can it be done? Using which object?

1 Answer 1

5

I just realized that my search for Author Apex on the PermissionSet fields missed one that is meant as a catch-all:

Field Name
PermissionsPermissionName

Type
boolean

Properties
Create, Filter, Update

Description
One field for each permission. If true, users assigned to this permission set have the named permission. The number of fields varies depending on the permissions for the organization and license type.

I debugged all the fields on PermissionSet and lo and behold, there is a field called PermissionsAuthorApex.

for (SObjectField field : SObjectType.PermissionSet.fields.getMap().values())
    if (String.valueOf(field).contains('Apex'))
        system.debug(field);

For completeness, you would run the following script to get this information (need more than one query):

Set<Id> permissionSetIds = new Map<Id, PermissionSet>([
    SELECT Id FROM PermissionSet WHERE PermissionsAuthorApex = true
]).keySet();
for (User user : [
    SELECT Name FROM User WHERE Id IN (
        SELECT AssigneeId FROM PermissionSetAssignment
        WHERE PermissionSetId IN :permissionSetIds
    )
]) system.debug(user);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .