Sub topic 6
Routing New Cases with Assignment Rules
Assignment rules decide who owns a new case. This chapter assumes you can navigate Setup, know what a queue is, and have seen the Case object. It covers how rules are built, how they are evaluated, and where they commonly fail.
How an assignment rule works
A case assignment rule is an ordered list of rule entries. Each entry has criteria and an assignee, which is a user or a queue. When a case is evaluated, Salesforce checks the entries in order of their sort number. The first entry whose criteria match wins, and evaluation stops. If no entry matches, the case goes to the default case owner set in Case Settings.
Only one assignment rule can be active at a time. You can keep several rules defined, but you must activate one.
Building a rule
- In Setup, search for Case Assignment Rules.
- Click New, name the rule, and check Active if it should be the live rule.
- Open the rule and click New under Rule Entries.
- Set the Sort Order, the criteria, and the assignee.
- Optionally choose an email template to notify the new owner.
Criteria can use field values or a formula. For example, an entry for urgent web cases could use these filters:
| Sort Order | Criteria | Assign to |
|---|---|---|
| 1 | Priority equals High AND Origin equals Web | Tier2_Support queue |
| 2 | Origin equals Email | General_Support queue |
| 3 | Subject contains "billing" | Billing queue |
Put the most specific entries first. An entry with broad criteria placed early will capture cases that a later, narrower entry was meant to handle.
When rules run
Rules do not run on every save. They run when:
- Web-to-Case or Email-to-Case creates the case, and the rule is active.
- A user creates a case in the UI with Assign using active assignment rule selected.
- Apex inserts a case and sets the DML option to use the rule.
A case created from Apex does not use the rule by default. This snippet applies the active rule on insert:
Case c = new Case(
Subject = 'Cannot log in to the portal',
Origin = 'Web',
Priority = 'High'
);
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule = true;
c.setOptions(dmo);
insert c;Common errors
- Case lands with the creator or the default owner. The rule was never triggered. Check that the checkbox was selected, or that the Apex code sets the DML option.
- Wrong queue chosen. An earlier entry with broader criteria matched first. Reorder the entries.
- Entry never matches. Criteria compare exact values. A picklist value that was renamed, or a text match with different spelling, will not match.
- Assignment to a queue fails. The queue must list Case in its supported objects. Otherwise it cannot be chosen as an assignee.
- Nothing happens at all. No rule is marked Active.
Quick check
Exercise
A case is created by Apex with Origin = 'Web' and Priority = 'High'. The active rule has entry 1 (Priority = High, assign to Tier2Support) and entry 2 (Origin = Web, assign to GeneralSupport). The case ends up owned by the user running the code. What is the most likely cause, and what fixes it?
Show answer
The assignment rule was never triggered, because Apex inserts do not run assignment rules by default. Create a Database.DMLOptions object, set assignmentRuleHeader.useDefaultRule = true, call setOptions on the case, and then insert it. With the rule triggered, entry 1 matches first and the case goes to Tier2_Support.