SEL_Group
Class · Group: Selectors
global inherited sharing class SEL_Group extends SEL_BaseExtends: SEL_Base
Selector for Salesforce Group objects. Provides query methods for group lookup and recursive group membership resolution including role-based groups, role hierarchies, and nested group membership.
Example
Group foundGroup = new SEL_Group().findByName('Approvers');
Boolean isMember = new SEL_Group().userIsInGroup(userId, 'Approvers');
List<User> members = new SEL_Group().findAllUsers(new Set<Id>{groupId});See Also: SEL_Base
Methods
| Method | Description |
|---|---|
| global List<User> findAllUsers(Set<Id> parentGroupIds) | Recursively finds all users contained within the specified public groups, including users from embedded roles, role hierarchies, and nested groups. |
| global Group findByName(String groupName) | Finds a Group by its Name field. |
| global override List<SObjectField> getFields() | Returns the default fields for Group queries. |
| global Boolean userIsInGroup(Id userId, String groupName) | Checks whether a user is a member of a named group. |
findAllUsers
global List<User> findAllUsers(Set<Id> parentGroupIds)Recursively finds all users contained within the specified public groups, including users from embedded roles, role hierarchies, and nested groups. This method handles complex group structures by:
Processing Role and RoleAndSubordinates groups
Traversing nested group memberships
Collecting users from role hierarchies
Avoiding infinite loops through iterative processing
Parameters
| Parameter | Type | Description |
|---|---|---|
parentGroupIds | Set | Set of Group IDs to analyze for user membership. |
Returns User — List of User records that are members of the specified groups (directly or indirectly).
Example
Set<Id> groupIds = new Set<Id>{ '00G3X000001AbcD' };
List<User> allUsers = new SEL_Group().findAllUsers(groupIds);findByName
global Group findByName(String groupName)Finds a Group by its Name field.
Parameters
| Parameter | Type | Description |
|---|---|---|
groupName | String | The Name to search for. |
Returns Group — The found Group, or null if not found.
Example
Group result = instance.findByName('myName');getFields
global override List<SObjectField> getFields()Returns the default fields for Group queries.
Returns SObjectField — List of SObjectField tokens to include in queries.
Example
List<SObjectField> result = instance.getFields();userIsInGroup
global Boolean userIsInGroup(Id userId, String groupName)Checks whether a user is a member of a named group.
Parameters
| Parameter | Type | Description |
|---|---|---|
userId | Id | The User Id to check. |
groupName | String | The Name of the group to check membership in. |
Returns Boolean — True if the user is a member of the group.
Example
Boolean result = instance.userIsInGroup(recordId, 'myName');Constructors
| Constructor | Description |
|---|---|
| global SEL_Group() | Constructs a new SEL_Group selector instance. |
SEL_Group()
global SEL_Group()Constructs a new SEL_Group selector instance.
Example
SEL_Group instance = new SEL_Group();