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.

Since: 1.0

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 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 getFields()Returns the default fields for Group queries.
global SEL_Group()Constructs a new SEL_Group selector instance.
global Boolean userIsInGroup(Id userId, String groupName)Checks whether a user is a member of a named group.

Method Details

SEL_Group

apex
global SEL_Group()

Constructs a new SEL_Group selector instance.

Since: 1.0

Example:

apex
SEL_Group instance = new SEL_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:

  • 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).

Since: 1.0

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:

  • groupName (String) - The Name to search for.

Returns: Group - The found Group, or null if not found.

Since: 1.0

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.

Since: 1.0

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:

  • 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.

Since: 1.0

Example:

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