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
SS KarthickSS Karthick 

Getting Group Id

Hi Everybody,
           Can anyone tell me how to get the group   Id based on user logged in 


Thanks in advance
Karthick
Best Answer chosen by SS Karthick
SravsSravs
The following query return a list of group membershipd for loggedin users, From this we can determine the Groups. 

system.debug([Select UserOrGroupId, Id, GroupId From GroupMember where UserOrGroupId =: UserInfo.getUserID()]);


All Answers

James LoghryJames Loghry
Can you provide more context around this?  A user can belong to more than one group, so are you trying to fetch all groups associated with a user or find the group that owns a record, etc?
SravsSravs
The following query return a list of group membershipd for loggedin users, From this we can determine the Groups. 

system.debug([Select UserOrGroupId, Id, GroupId From GroupMember where UserOrGroupId =: UserInfo.getUserID()]);


This was selected as the best answer