function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Apex Managed Sharing - Querying a Group (Role)

Hello all,


I have been trying to query the Group table to get roles with the name "Hiring Manager"


List<Group> groups = [SELECT Name, Id FROM Group where Name = 'Hiring Manager'];
        hiringManagerShare.UserOrGroupId = groups[0].Id;



Can't seem to get any rows out of this. I double checked on the role's label, it is the same as above. If i remove the Where clause, everything works..


Please help!


Hi all,


I would appreciate any help on this. This is really weird because I was able to get the results if I leave out the Name clause!


I dont see any problem with the code i got the result for that by querying the same way


Thanks for the reply. I tried printing out by using system.debug and whenever I use .Name to print it, it seems to be null, what did I do wrongly? I double checked my role and the label name is correct..


I created a public group with label 'Hiring Manager' and i wrote the below query in "Developer Console" and that particular


row was fetched perfectly


List<Group> groups = [SELECT Name, Id FROM Group where Name = 'Hiring Manager'];


Sory i got your point now, if its based on role go for Developer Name field instead of Name field


List<Group> groups = [SELECT Name, Id,DeveloperName FROM Group where DeveloperName = 'HiringManagerA'];
System.debug(groups.get(0).DeveloperName );



Please mark solved if it solves your issue, so that everyone can leverage this







Many thanks but this does not give me any records back either...


Still you didn't get any records from the above query? I've made some changes in query