Skip to content

SEL_Group

Class · Group: Selectors

apex
global inherited sharing class SEL_Group extends SEL_Base

Extends: 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

apex
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

MethodDescription
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

apex
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

ParameterTypeDescription
parentGroupIdsSetSet 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

apex
Set<Id> groupIds = new Set<Id>{ '00G3X000001AbcD' };
List<User> allUsers = new SEL_Group().findAllUsers(groupIds);

findByName

apex
global Group findByName(String groupName)

Finds a Group by its Name field.

Parameters

ParameterTypeDescription
groupNameStringThe Name to search for.

Returns Group — The found Group, or null if not found.

Example

apex
Group result = instance.findByName('myName');

getFields

apex
global override List<SObjectField> getFields()

Returns the default fields for Group queries.

Returns SObjectField — List of SObjectField tokens to include in queries.

Example

apex
List<SObjectField> result = instance.getFields();

userIsInGroup

apex
global Boolean userIsInGroup(Id userId, String groupName)

Checks whether a user is a member of a named group.

Parameters

ParameterTypeDescription
userIdIdThe User Id to check.
groupNameStringThe Name of the group to check membership in.

Returns Boolean — True if the user is a member of the group.

Example

apex
Boolean result = instance.userIsInGroup(recordId, 'myName');

Constructors

ConstructorDescription
global SEL_Group()Constructs a new SEL_Group selector instance.

SEL_Group()

apex
global SEL_Group()

Constructs a new SEL_Group selector instance.

Example

apex
SEL_Group instance = new SEL_Group();