I have few public groups where I have only roles added. Is there any way to identify whether the current user is part of the group by taking current user's role and then comparing with the roles added in the group?
I would like to build a SOQL to check whether my current user is part of the group, but with below SOQL it is returning always false –
SELECT GroupId,UserOrGroupId FROM GroupMember WHERE GroupId =: <-----> AND UserOrGroupId =: <---->
Best Answer
Since Role is mapped in user record so retrieve
UserRoleId
from UserIn the
Group
object ,RelatedId
field stores following types of values:Though
Group
can have otherType
as follows which doesn't haveRelatedId
So, final query will be like this
Also, refer Fetch public groups for a user via Apex for all types of complex scenarios.
Here is an example from my DE
SOQL and results