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
jiro ymdjiro ymd 

How to get role from public groups?

Hello.
I can get user and public groups from public groups this SOQL,
but public groups add role, can not get add role.
How to get role from public groups?
[SELECT Id, DeveloperName, (SELECT UserOrGroupId FROM GroupMembers)
FROM Group WHERE DeveloperName IN :xxxxxx]
Best Answer chosen by jiro ymd
Abdul KhatriAbdul Khatri
you might need to do something like this
 
List<Group> groupRoleList = [SELECT Id FROM Group Where Type = 'Role'];

List<Group> groupList = [SELECT Id, DeveloperName, (SELECT UserOrGroupId FROM GroupMembers WHERE UserOrGroupId IN :groupRoleList) FROM Group WHERE DeveloperName IN :xxxxxx AND Type = 'Regular'];

All Answers

Abdul KhatriAbdul Khatri
you might need to do something like this
 
List<Group> groupRoleList = [SELECT Id FROM Group Where Type = 'Role'];

List<Group> groupList = [SELECT Id, DeveloperName, (SELECT UserOrGroupId FROM GroupMembers WHERE UserOrGroupId IN :groupRoleList) FROM Group WHERE DeveloperName IN :xxxxxx AND Type = 'Regular'];
This was selected as the best answer
NagendraNagendra (Salesforce Developers) 
Hi Jiro,

Sorry for this issue you are facing.

May I suggest you please give a try by using the below query.
SELECT Id,Name,DeveloperName,RelatedId,Type FROM Group 
WHERE RelatedId IN 
     (SELECT UserRoleId FROM User WHERE Id = <UserId>) 
AND Type = 'Role'
Please let us know if this works.

Kindly mark this as solved if the reply was helpful.

Thanks,
Nagendra
 
jiro ymdjiro ymd
Thank you All.
I get role from public groups.