Sub topic 4
Queues as lead owners
This chapter assumes you can find your way around Setup and the Object Manager. It also assumes you know what a lead is, and you can read basic Apex and SOQL for the code sections. Assignment rules come in the next chapter, but you need queues first, because most rule entries end by naming one.
What a queue is
A queue is a shared holding place for records. A record owned by a queue has no individual owner yet. It waits until a member of the queue claims it, or until someone or something assigns it to a user.
Queues solve a common lead problem. A new lead arrives and you know which team should handle it, but not which person. Without a queue you would have to pick a person, which creates a bottleneck, or leave the lead with a default owner who isn't responsible for it. With a queue, the whole team sees the lead and one of them takes it.
Some facts to keep in mind:
- A queue is not a user. It can't log in, doesn't consume a license, and has no profile.
- A queue can own records of any object you add to its Supported Objects list. For lead queues, that list must include Lead.
- Queues don't give anyone object permissions. A member who lacks Read and Edit on Lead through a profile or permission set still can't work the leads.
Creating a lead queue
Go to Setup, search for Queues, and click New. The fields that matter are:
| Field | Purpose |
|---|---|
| Label | The name users see when picking the queue as an owner. |
| Queue Name | The API-style name (developer name). Apex and metadata use it. |
| Queue Email | An address that receives notifications when a record is assigned to the queue. |
| Send Email to Members | If checked, each member also gets the notification. |
| Supported Objects | The objects whose records the queue may own. Add **Lead**. |
| Selected Members | The users, public groups, roles, or roles with subordinates that belong to the queue. |
Membership can be mixed. You can add individual users, a public group, and a whole role in one queue. Because membership can come from groups and roles, a large queue is often easier to maintain by pointing it at a public group than by listing people.
How records move through a queue
The usual life of a queue-owned lead has four steps. The lead is created or reassigned with the queue as owner. Members are notified if email is on. A member claims the lead, which sets the owner to that user. The owner works the lead and eventually converts it.
In the Lightning UI, a user can claim a queue-owned lead in a few ways:
- Open a list view that shows leads owned by the queue and change the owner of the selected records to themselves.
- Open the lead record and use Change Owner, choosing their own name.
- Use a list view with an Accept action if your administrator has added one to the layout.
A common setup is a list view called something like "Unclaimed Inbound Leads", filtered to leads owned by the queue and sorted by created date. Pin it for the sales team so the queue is visible without hunting for it.
Who can see and take queue records
Visibility depends on your sharing model for leads. If the organization-wide default for Lead is Private, queue members can see and act on the records the queue owns. Users above a member in the role hierarchy can also see them when hierarchy access is on for the object. Users who aren't members and who sit outside that hierarchy can't see them unless another sharing mechanism applies.
A user can take ownership of a queue's record if they are a member of the queue, or if they hold object permissions and sharing access that allow ownership changes. Queue membership alone gives access to the records. It doesn't give the permissions needed to edit them.
Queues in assignment and capture
Queues appear in several places in the lead process:
- Assignment rule entries. Each entry assigns to a user or a queue. The next chapter builds these in detail.
- Default lead owner. In Lead Settings, the default lead owner can be a user or a queue. It catches leads that no rule entry matches. This setting matters for Web-to-Lead, where there is no logged-in user to become the owner.
- Manual and API assignment. Anyone with the right permissions can set a lead's owner to a queue, and Apex can set
OwnerIdto a queue Id.
The default lead owner is the safety net. If your Web-to-Lead form runs with no rule, or the rule has no matching entry, leads land with the default owner. Making that a queue that the sales operations team monitors prevents leads from silently piling up under one person's name.
Working with queues in Apex and SOQL
A queue is a record of the Group object with Type = 'Queue'. Its Id starts with the prefix 00G. The OwnerId field on a lead is polymorphic, so it holds either a user Id or a queue Id.
This code creates a lead and assigns it directly to a queue:
Group q = [
SELECT Id
FROM Group
WHERE Type = 'Queue' AND DeveloperName = 'Inbound_Leads'
LIMIT 1
];
Lead l = new Lead(
FirstName = 'Grace',
LastName = 'Hopper',
Company = 'Compiler Works',
Email = '[email protected]',
LeadSource = 'Web',
OwnerId = q.Id
);
insert l;
System.debug('Owner is queue: ' + (l.OwnerId == q.Id));Setting OwnerId yourself and running an assignment rule in the same operation are two ways to choose an owner. If you also pass DMLOptions that use the active rule, the rule decides the owner. Pick one approach per code path so the result is predictable.
Claiming a lead is a normal owner change:
Id leadId = [
SELECT Id
FROM Lead
WHERE Email = '[email protected]'
LIMIT 1
].Id;
Lead toClaim = new Lead(Id = leadId, OwnerId = UserInfo.getUserId());
update toClaim;To find leads still sitting in queues, filter on the owner's type:
SELECT Id, Name, Company, CreatedDate, Owner.Name
FROM Lead
WHERE Owner.Type = 'Queue' AND IsConverted = false
ORDER BY CreatedDate ASC
LIMIT 50The oldest unclaimed leads come first. This is the basis of a "leads waiting too long" report or a scheduled alert.
To list the queues that accept leads, query the join object QueueSobject:
SELECT Queue.Name, Queue.DeveloperName, SobjectType
FROM QueueSobject
WHERE SobjectType = 'Lead'Queues and conversion
Conversion creates an account, a contact, and optionally an opportunity, and each of those needs an owner who is a real user. A lead that is still owned by a queue hasn't been taken by anyone, so the normal practice is that a user claims it before converting. Check how your org's convert screen behaves with a queue-owned lead in a sandbox, because the available owner choices on the convert screen are worth knowing before you build automation that depends on them.
For automation, the safest design is to resolve the owner first. Assign the lead to a user, then convert it, rather than relying on the conversion step to decide who ends up owning the new records.
Common problems with queues
| Symptom | Likely cause | Fix |
|---|---|---|
| Queue doesn't appear as a choice when assigning leads | Lead isn't in the queue's Supported Objects | Edit the queue and add Lead. |
| Members can see leads but can't edit them | Profile or permission set lacks Edit on Lead | Grant the object permission. Membership does not. |
| Members get no emails | Send Email to Members is off, or no Queue Email is set | Turn on the setting or add an address. |
| A user can't see a queue's leads | Not a member, and not above a member in the hierarchy | Add them to the queue or adjust sharing. |
| Leads stay unclaimed for days | No visible list view, no alert | Pin an unclaimed-leads list view and report on age. |
| Queue can't be deleted | Records or rule entries still reference it | Reassign the records, update the rule entries, then retry. |
Design guidance
- Create queues by team or purpose, such as region, product line, or lead source, rather than one giant queue. Small queues make it clear who is responsible.
- Base membership on public groups or roles so that people joining or leaving a team don't require editing many queues.
- Choose one default lead owner queue and monitor it. Leads there signal that your assignment rules have a gap.
- Keep queue names descriptive and stable, since code and metadata reference the developer name.
- Test with a user who is only a queue member, not an administrator. Administrators see everything and hide permission and sharing problems.
Exercise
A member of the "Inbound Leads" queue can see a lead owned by the queue but gets an error when trying to edit it. The queue has Lead in Supported Objects. What is the most likely cause, and how do you fix it?
Show answer
Queue membership grants access to the records but not object permissions. The user's profile or permission sets probably lack Edit on the Lead object. Grant Edit (and Read) on Lead through a profile or permission set.
Exercise
Write a SOQL query that returns unconverted leads currently owned by any queue, oldest first.
Show answer
SELECT Id, Name, Company, CreatedDate, Owner.Name FROM Lead WHERE Owner.Type = 'Queue' AND IsConverted = false ORDER BY CreatedDate ASC
Exercise
Why is it a good idea to make the default lead owner in Lead Settings a monitored queue instead of one person?
Show answer
Leads that no assignment rule entry matches, including many Web-to-Lead submissions, go to the default owner. A monitored queue makes those leads visible to a team and shows gaps in the rules. A single person's name hides them and creates a bottleneck.