0

this one should be a quick one. We had a request from our Admins to use PermissionSetGroups rather than merely using the PermissionSets.

I'm messing around with it a bit and noticed that the PermissionSetGroup does not add the PermissionSets to the user. Does not appear that you can access these permissionSets 'names' from the PermissionSetGroup. Is this accurate?

I would have expected a List field on the PermissionSetGroups, but couldn't find anything online or in the docs on how to access.

Anyone else struggling with this? Anyone have any solutions?

IMG_Explaination:

TestGroup is the PermissionSetGroup and contains Test1 and Test2. Manually Added the PermissionSets to get them into the query results

TestGroup is the PermissionSetGroup and contains Test1 and Test2. Manually Added the PermissionSets to get them into the query results

1
  • One caveat I learned recently is users will need the View Setup and Configuration permission to read the tables behind permission sets. So if that's turned off, the Apex queries may not work when run under those users' identities.
    – Ken
    Commented Nov 26 at 19:46

2 Answers 2

4

A handy resource for understanding this is the schema doc in Salesforce Object Reference. You can see Profile and Permission Objects and note that there is a junction record called PermissionSetGroupComponent between PermissionSetGroup and PermissionSet

enter image description here

So, to get a list of the component PermissionSets in a PermisisonSetGroup

SELECT Developername, 
  (SELECT PermissionSet.Name 
      FROM PermissionSetGroupComponents) 
 FROM PermissionSetGroup
3
  • cropredy, I'm not sure this query works. Its saying that there is no column When I run the query in Apex...
    – thinker
    Commented Feb 4, 2022 at 16:30
  • List<PermissionSetGroup> psg = [SELECT Developername, (SELECT PermissionSet FROM PermissionSetGroupComponents) FROM PermissionSetGroup]; System.debug(psg.size());
    – thinker
    Commented Feb 4, 2022 at 16:30
  • 1
    you subquery is missing the .Name
    – cropredy
    Commented Feb 4, 2022 at 20:13
0

THanks to @cropredy for getting the schema. That's helpful, this code snippet should provide more clarity for people on the forums that are looking for the recipe to access these things.

List<PermissionSetGroup> psg = [
   SELECT Developername, 
          (SELECT 
            Id, 
            PermissionSet.Name 
           FROM 
            PermissionSetGroupComponents
          )
   FROM PermissionSetGroup 
   WHERE DeveloperName ='TestGroup'
];

System.debug(psg.size()); // Validate the query is getting the permission set groups

List<PermissionSetGroupComponent> comp = psg.get(0).PermissionSetGroupComponents; //Might be a more efficient way to do this next bit. . . 

System.debug(comp.Size()); // confirm that the group components junction object list was configured correctly. 

//Loop through permissionSet.Name to determine if the user has the permission sets. 
for ( PermissionSetGroupComponent c : comp ){
    System.debug(c.PermissionSet.Name); 
}

You must log in to answer this question.

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