Sub topic 4
Who owns a case: users and queues
Every case has exactly one owner. The owner decides who sees the case first, who is expected to work on it, and which list views and reports show it. This chapter covers the two kinds of owner, how they differ in behavior, and how to find and set them. It assumes you know your way around Setup and list views, and you understand users, profiles, and permission sets. The code sections use simple SOQL and Apex.
The owner is a single polymorphic field
A case stores its owner in the standard field OwnerId. The field is polymorphic, which means one field can point to records of different objects. For a case, OwnerId holds the Id of one of two things:
- A User record. This is an individual agent or manager.
- A Group record whose
TypeisQueue. This is a shared holding area for a team.
Public groups are also stored as Group records, but a case cannot be owned by one. Only queues can own cases. A case cannot have an empty owner either. If you do not set one, Salesforce uses the creating user, or whatever owner an assignment rule picks.
User ownership
When a user owns a case, one named person is accountable for it. This has several consequences:
- The case appears in that user's "My Cases" style list views.
- Reports filtered by "My cases" include it.
- The owner can edit it if their profile and permission sets grant the access, and sharing rules can extend access to other users.
- Notifications about case changes, such as comments and escalations, usually go to the owner.
The owner must be an active user. You cannot assign a case to a deactivated user, and cases left with a user who has left the company are a common cause of stuck work. Reassign them before you deactivate the person.
Queue ownership
A queue is a shared owner for a group of people. A case owned by a queue is waiting: the team can see it, but no individual has taken it yet. Queues are useful when:
- Work arrives faster than a person can be chosen, such as a new Web-to-Case submission.
- A team shares responsibility, such as Tier 2 Support or Billing.
- You want agents to pull work instead of having it pushed to them.
A queue has three parts that matter for ownership:
- The members. These can be users, public groups, roles, or roles with subordinates. Only members of the queue, and users above them in the role hierarchy when "Grant Access Using Hierarchies" is on, get access to the queue's cases through ownership.
- The supported objects. A queue can own only the objects you list for it. If Case is not in the list, you cannot assign cases to that queue.
- An optional queue email address. Salesforce can notify this address, or the members, when a record arrives in the queue.
Chapter 5 covers creating and managing queues in detail. Here we focus on what queue ownership does to a case.
How a queue case reaches a person
A queue is not a person, so nobody is working a case while a queue owns it. A queue case becomes a user case in one of these ways:
- A member opens a queue list view and clicks Accept. This changes the owner to that member.
- A manager or member uses Change Owner and picks a user.
- An escalation rule, assignment rule, flow, or Apex code sets
OwnerIdto a user. - In Omni-Channel setups, the routing system pushes the case to an available agent. The Omni-Channel chapter covers this.
Ownership moves in the other direction too. An agent can use Change Owner to send a case back to a queue, for example when handing off from Tier 1 to Tier 2.
Comparing the two owners
| Aspect | User owner | Queue owner |
|---|---|---|
| Meaning | One person is working it | The team has it, nobody has taken it |
| `OwnerId` points to | User | Group where `Type = 'Queue'` |
| Who can see it | Owner, plus anyone granted access by sharing, hierarchy, or profile permissions | Queue members, plus users above them in the hierarchy, plus anyone granted access by other sharing |
| Typical list view | My Cases | Unassigned or team queue view |
| Risk | Case stalls if the person is absent | Case sits unclaimed if nobody watches the queue |
| Can own a case | Active users only | Only if Case is a supported object of the queue |
Visibility and access
Ownership interacts with your sharing settings. If the organization-wide default for Case is Private, a user can see a case only if they own it or sharing gives them access. Queue membership is one form of that access. This is why a case that goes to a queue the agent is not in will vanish from that agent's lists, even though they created it. Test this with a real agent profile, not only as an administrator, because administrators with "View All" never show this problem.
Also keep in mind that accepting a case from a queue moves it out of shared visibility and into the personal ownership of one user. After that, other queue members may lose access unless they are above the owner in the hierarchy or a sharing rule covers them.
Reading and setting the owner in SOQL and Apex
The Owner relationship on Case is polymorphic, so you can filter on Owner.Type to tell queues from users. This query finds open cases that nobody has picked up yet. Run it in the Developer Console Query Editor, or in Apex with Database.query or inline SOQL.
SELECT Id, CaseNumber, Subject, Status
FROM Case
WHERE Owner.Type = 'Queue' AND IsClosed = false
ORDER BY CreatedDate ASCThe oldest cases come first, so the top of the result is the work that has waited longest. Adding Owner.Name to the field list shows which queue holds each case.
To assign a case to a queue from Apex, look up the Group record and use its Id as the owner. Queue names are not guaranteed to stay the same, so filter on DeveloperName, which is the API name and rarely changes.
Group tier2 = [
SELECT Id
FROM Group
WHERE Type = 'Queue' AND DeveloperName = 'Tier2_Support'
LIMIT 1
];
Case c = new Case(
Subject = 'Data export fails',
Origin = 'Email',
OwnerId = tier2.Id
);
insert c;If the query returns no rows, Apex throws a QueryException at the assignment. In real code, query into a list and check that it is not empty, as the next example does. The query will also find nothing if no queue has that developer name, so check the spelling against Setup.
To check what kind of owner a case has in Apex, you do not need a query. The Id prefix tells you the object type.
public with sharing class CaseOwnerUtil {
public static Boolean isQueueOwned(Case c) {
return c.OwnerId.getSObjectType() == Group.SObjectType;
}
public static Id queueIdByDeveloperName(String developerName) {
List<Group> queues = [
SELECT Id
FROM Group
WHERE Type = 'Queue' AND DeveloperName = :developerName
LIMIT 1
];
return queues.isEmpty() ? null : queues[0].Id;
}
}isQueueOwned returns true for any Group owner. Because only queues can own cases, that is equivalent to a queue check. The queueIdByDeveloperName helper returns null when the queue is missing, so the caller decides whether to fail or fall back.
Common mistakes
- Assigning to a queue that does not support Case. The save fails with an error about an invalid owner. Add Case to the queue's supported objects.
- Hard-coding queue Ids. Ids differ between sandboxes and production. Look the queue up by
DeveloperName. - Forgetting that Change Owner can notify. In the UI, the change owner dialog has a notification checkbox. If you leave it unchecked, a new owner may not learn about the case.
- Leaving cases with inactive users. Reassign open cases before deactivating an agent. A queue is a good temporary home.
- Treating the queue as a person in reports. A report grouped by Case Owner mixes users and queues. Filter or group on owner type when you want only agent workload.
- Expecting a queue to work cases. A queue owner means the case is unclaimed. Without a list view and someone watching it, queue cases age quietly. Escalation rules, covered later, are the safety net.
Exercise
A new Case is inserted from Apex with OwnerId set to the Id of the Group record for the Tier2_Support queue. A manager then runs the query "SELECT Id FROM Case WHERE Owner.Type = 'Queue' AND IsClosed = false". Will the new case appear in the results? If agent Priya clicks Accept on it in a list view, what happens to its OwnerId, and will the same query still return it?
Show answer
Yes, the case appears, because its owner is a queue and it is not closed. When Priya clicks Accept, OwnerId changes from the queue's Group Id to Priya's User Id. After that, Owner.Type is User, so the query no longer returns the case.