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
ForceLoverForceLover 

GroupMember issue

Hi Everyone,

 

I have 3 queues in my dev.org i want to find the present login user is member of which queue.how i can find this.Thanks in advance

sfdcfoxsfdcfox
You should be able to query: SELECT UserId, UserOrGroupId FROM GroupMember WHERE UserId = :UserInfo.getUserId() AND UserOrGroupId = :queue.Id, where queue is an SObject of type Group (queried by SELECT Id FROM Group WHERE Type = 'Queue' and Name = 'Queue Name').
ForceLoverForceLover

yes i tried something like this,but i don't want to give the queue name in the query it should check all the queues.I think there is no such field usereid in the Groupmember object

 

ConvertLeadsController Compile Error: No such column 'UserId' on entity 'GroupMember'.

 

ID uid = userinfo.getuserid();

List<Group> g = [select id, Name from Group where Type = 'Queue'];

System.debug('@@@@@'+g.size());---------output is 3

List<GroupMember> gm = [Select Id, GroupId, UserOrGroupId From GroupMember  where UserOrGroupId =:uid];

system.debug(gm);----------output is 0

 

but my present login user is member for 2 queues

sfdcfoxsfdcfox

It doesn't seem possible at the moment actually, if you add members to groups by role instead of by group. If anyone else knows how to do this, input would be appreciated.

sfdcfoxsfdcfox
Actually, it appears that you have to:

1) Query Group.Id for RelatedId = :UserInfo.getUserRoleId()
2) Query GroupMember.GroupId for UserOrGroupMember IN (results from #1)
3) Query Group.Name for Id IN (results from 2).
ForceLoverForceLover
i'm sorry ,you are correct by the moment i add members to the queue from roles only.If i change my queue members from roles with users or a public group will i get this.
ForceLoverForceLover
List<Group> g = [select id, Name,RelatedId from Group where Type = 'Queue' AND RelatedId=:UserInfo.getUserRoleId()];

System.debug('@@@@@'+g.size());

It is giving the list size is zero.
ForceLoverForceLover

Actually i want to restrict my users to convert their own leads along with queue leads in which they are a member.I override my standard convert button with a VF which will perform lead convertion.I want to put these conditions in the controller

 

1)  Sales Rep can convert their own leads, and Lead owned by a Queue they are a member of

 

2) If Sales Rep converts a lead owned by a Queue , then change ownership Contact, Account, Opportunity to Sales Rep user who is converting.

 

3) Sales Manager and Executive can convert their teams' leads. If a Sales Manager or Executive converts a sales user's Lead, ownership of lead, opportunity, account and contact should remain sales rep

 
Sales Rep ,Manager,Executive are the roles of my users in the org.