Sub topic 5
Public groups and queues as sharing targets
Earlier chapters covered the baseline (org-wide defaults) and the role hierarchy. Before you build sharing rules, you need to know what they point at. Most sharing rules grant access to a set of people, and that set is usually a public group. This chapter covers public groups, queues, and the places each one is used.
This chapter assumes you know what a role is, what org-wide defaults do, and how to open Setup. The optional code sections assume basic SOQL.
Why groups exist
A sharing rule needs a "share with" target. You could target one role, but real requirements rarely follow the org chart. "All invoice approvers" might include two roles, three named people, and a regional team. A public group lets you define that collection once and reuse it everywhere.
Groups also make maintenance cheaper. When someone joins the approvers, you add them to the group. You don't edit each rule that grants access to approvers.
Public groups
A public group is a named collection of members. An administrator creates it in Setup under Users, then Public Groups. A group can contain any mix of these member types:
- Individual users
- Roles
- Roles and subordinates (and, if portals or Experience Cloud are in use, their role variants)
- Territories, if Territory Management is enabled
- Other public groups
Because groups can contain other groups, you can build layers. A group named All_Finance might contain Finance_Managers, Finance_Analysts, and one user who works across both.
Everyone in the nested structure receives whatever access is granted to All_Finance. Nesting cannot be circular. Group A cannot contain group B if B already contains A.
Grant Access Using Hierarchies
Each public group has a "Grant Access Using Hierarchies" setting, which is on by default. When it is on, users above a member in the role hierarchy also get the access that the group receives. This matches how the hierarchy normally works for owned records.
If you turn it off, only the group's direct members get the access. Managers above them do not inherit it through this group. Turn it off only when you have a clear reason, such as restricting sensitive records even from the people up the hierarchy. Otherwise a missing manager in the results of a troubleshooting query is hard to explain.
Roles inside groups
A group that contains a role does not hold the people in that role. It holds a reference to the role. When someone changes role, their access through the group changes with them, with no edit to the group itself. This is the main advantage of putting roles in groups instead of listing users.
Queues
A queue is a holding place for records that nobody owns yet. A queue can be the owner of a record, so a record can wait there until a user claims it. Typical uses are support cases waiting for triage and leads waiting for assignment.
You create a queue in Setup under Queues. A queue has two main settings:
- Supported objects. Queues work only for objects you select, such as Case, Lead, and enabled custom objects. Accounts and opportunities cannot be owned by a queue.
- Queue members. These can be users, public groups, roles, or roles and subordinates.
Queue members can view and take ownership of the records the queue owns, as long as their object permissions allow it. With "Grant Access Using Hierarchies" in effect, managers above a queue member can usually see the records too.
Groups and queues compared
| Aspect | Public group | Queue |
|---|---|---|
| Purpose | Collect people as a sharing target | Own records until a user takes them |
| Can own records | No | Yes, for supported objects |
| Can contain | Users, roles, territories, other groups | Users, public groups, roles |
| Appears in "share with" lists of rules | Yes | No. Put the members in a public group to use them as a target |
| Typical use | "Share overdue invoices with Finance Managers" | "New cases wait for the support team" |
The two are often confused because both contain people. The question to ask is "does this thing need to own records?" If yes, use a queue. If it only needs to receive access, use a public group.
Where groups are used
Public groups appear in several later mechanisms:
- As the "share with" target of owner-based and criteria-based sharing rules.
- As the "owned by members of" source in owner-based rules.
- As the target when you share one record manually.
- As a queue member.
- In some other places, such as folder sharing for reports and dashboards.
Because they are used so widely, a change to group membership can change access in many places at once. Adding a user to Finance_Managers grants every rule that targets that group, including rules you may have forgotten about.
Inspecting groups with SOQL
Groups, queues, and their members are stored as records. The Group object holds both public groups and queues, distinguished by Type.
SELECT Id, Name, DeveloperName, Type
FROM Group
WHERE Type IN ('Regular', 'Queue')
ORDER BY Type, NameRegular is a public group. To see what a group directly contains, query GroupMember:
SELECT Id, GroupId, UserOrGroupId
FROM GroupMember
WHERE Group.DeveloperName = 'Finance_Managers'UserOrGroupId holds either a user Id or another group Id. A role you added to a public group appears as a separate internal Group record whose Type is Role or RoleAndSubordinates. Check the Id prefix, or join to Group, to tell the cases apart. GroupMember shows only direct members. To find everyone with access, you must follow nested groups yourself.
To see which objects a queue supports, query QueueSobject:
SELECT QueueId, Queue.Name, SobjectType
FROM QueueSobject
WHERE Queue.DeveloperName = 'Support_Triage'Changing membership with Apex
Admins usually manage membership in Setup, but you can also do it in code. This anonymous Apex adds the running user to a public group:
Group financeManagers = [
SELECT Id
FROM Group
WHERE DeveloperName = 'Finance_Managers' AND Type = 'Regular'
LIMIT 1
];
GroupMember member = new GroupMember(
GroupId = financeManagers.Id,
UserOrGroupId = UserInfo.getUserId()
);
Database.SaveResult result = Database.insert(member, false);
if (!result.isSuccess()) {
System.debug(result.getErrors()[0].getMessage());
}Common errors
- Using a queue as a sharing target. Queues are owners, not "share with" targets. Put the same people in a public group and target that group.
- Listing users instead of roles. Named users go stale when people change jobs. Use a role or a role-based group when the requirement is really about a function.
- Overlapping nested groups. Deep nesting makes it hard to answer "why does this person have access?" Keep nesting to two or three levels and give groups names that state their purpose, such as
Finance_Managersinstead ofGroup_7. - Deleting a group still in use. Salesforce blocks deletion while sharing rules or other configuration reference the group. Remove those references first.
- Forgetting recalculation. Changing group membership triggers sharing recalculation. In orgs with large data volumes, this can take time before access is correct. The recalculation chapter covers that in detail.
Exercise
The support team wants new Case records to wait in a shared pool until an agent claims them. Separately, the same team should receive read access to Case records owned by the sales team through a sharing rule. Which do you create for each need, a queue or a public group, and why?
Show answer
Create a queue for the waiting pool, because a queue can own Case records until an agent takes ownership. Create a public group (or reuse one with the same members) as the "share with" target of the sharing rule, because queues are not offered as sharing rule targets and a group only needs to receive access, not own records.
Exercise
A public group named Finance_Managers contains the role Finance Managers. A new finance manager is assigned to that role. Do you need to edit the group so the new manager gets the access that sharing rules grant to the group? What would you query to confirm which members the group holds directly?
Show answer
No. The group references the role, so a user who moves into the role gets the group's access automatically, after sharing recalculation finishes. To see the direct members, query GroupMember filtered by the group, for example SELECT Id, GroupId, UserOrGroupId FROM GroupMember WHERE Group.DeveloperName = 'Finance_Managers'. The role appears there as an internal Group record, not as individual users.