2

I'm not sure about the object name and the Field Name. I tried but i think "ApexClass" is not the right object to call apexclass from a permission set. Here is the query [Select Id, Name From ApexClass] but its not giving the enabled classes in a permissionSet.

Thanks in Advance

2
  • Can you please give more detail of your issue "Apex Class Accesses of a permossionset"? Jul 22, 2019 at 6:14
  • For every permission set we will have some object settings, apex class access, Visual force page access where u can give access to a particular page or object or class for a user or a profile. U can do it manually by navigating through Permission Sets -> "click on any permission" -> Apex class access -> Edit -> Enable. So inorder to view the enabled classes i am searching for a perfect QUERY
    – Lokesh
    Jul 22, 2019 at 6:22

2 Answers 2

8

You can use SetupEntityAccess and Apex class to get required information.

First SOQL will show all apex class Ids which is enabled for permission set 'CustomPermission'.

Second SOQL will show Apex Class Name based on first query result.

Map<ID,AggregateResult> mapAccess=new Map<Id, AggregateResult>([SELECT SetupEntityId Id
FROM SetupEntityAccess where Parent.Name='CustomPermission' and SetupEntityType='ApexClass' GROUP By SetupEntityId]);

List<ApexClass> apexClasses=[Select Name from Apexclass where id in:mapAccess.keyset()];

System.debug(apexClasses);
8
  • Thank u so much for the idea @Dhanik definitely this will work and i have one more doubt .What is the object name used for APexClassAccess? Example: For Object settings in a permission set we have "Object Permissions"
    – Lokesh
    Jul 22, 2019 at 9:10
  • I am trying to import Apex Class Access to a particular permission set using its ID from a csv file. Its quite complicated but i will sort it out only if found the object name for Apex class access relational to permission set since "ApexClass" is not working(only for importing its not working,Export is good) as u have entered in the above Query
    – Lokesh
    Jul 22, 2019 at 9:46
  • ApexClassAccess can be accessed using object SetupEntityAccess. You can combine all PermssionSet Id from CSV and pass that in first query. Jul 22, 2019 at 10:06
  • POpping Error : Invalid initializer type List<SetupEntityAccess> found for Map<Id,AggregateResult>: expected a Map with the same key and value types, or a valid SObject List. I think it wont handle colabration of SetupEntityAccess (MAP)with Apex class(LIST)
    – Lokesh
    Jul 22, 2019 at 12:11
  • Looks like you have not declared Map properly. Both side should be Map<ID,AggregateResult>. Use provided code, it is working as expected. Jul 22, 2019 at 13:01
3

As per the documentation of SetupEntityAccess at https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_setupentityaccess.htm

SetupEntityAccess - Represents the enabled setup entity access settings (such as for Apex classes) for the parent PermissionSet

In this SetupEntityId represents the ID of the entity for which access is enabled, such as an Apex class or Visualforce page. SetupEntityType - ApexClass for Apex classes

Below code returns all permission sets that grant access to the helloWorld Apex class:

SELECT Id, Name,
   (SELECT Id, Parent.Name, Parent.Profile.Name
   FROM SetupEntityAccessItems)
FROM ApexClass
WHERE Name = 'helloWorld'
1
  • Thank u for the [email protected] came to know about SystemEntityAccess while searching but how can i fetch all the classes from a particular permssionset and have a separate column in a query to identify whether the class is enabled or not (For eg., TRUE if it is enabled and FALSE otherwise).Is it possible and do we have field to make it possible? ...Help would be very usefull. Thanks
    – Lokesh
    Jul 22, 2019 at 6:35

You must log in to answer this question.

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