Search code examples
salesforceapex-codeapexsoql

SOQL child related list from User object


I would like to use a SOQL Query to load what is displayed at a user record, what I want to get is the:

  1. Permission Set Assignments Related list records
  2. Public Group Membership Related list records
  3. Queue Membership Related list Records

I am currently able to retrieve the permission set Related list records for a particular user but I am unable to get the public group and the queue membership related list records,

Here is my query:

SELECT Id, name, (select PermissionSet.Name, AssigneeId 
FROM PermissionSetAssignments) from user

Could you please help me adding the missing part in the query to get the queues and the public groups,

Thanks for your help.


Solution

  • You will not get Public group and Queue membership details directly from user object. You need additional query.

    SELECT Id, GroupId, UserOrGroupId 
    FROM GroupMember 
    WHERE UserOrGroupId IN (SELECT Id FROM User)
    

    Since queue is a public group you don't need additional query to get queue membership. This single query is enough.