Automate Case Routing
By the end of this lesson, you'll be able to:
- Handle a Case that doesn't match any configured routing rule
- Assign a sensible default queue as a fallback
- Explain why silent non-routing would be a worse outcome than a fallback
Prerequisites: "Build Configurable Business Rules (Custom Metadata)"
The gap: an unmatched Case
for (Case c : newCases) {
String key = c.Priority + '|' + c.Type;
if (queueByPriorityAndType.containsKey(key)) {
c.Assigned_Queue__c = queueByPriorityAndType.get(key);
}
// what if there's no matching rule at all?
}
for (Case c : newCases) {— loops over the new Cases.String key = c.Priority + '|' + c.Type;— builds the composite key.if (queueByPriorityAndType.containsKey(key)) {— checks the lookup.c.Assigned_Queue__c = queueByPriorityAndType.get(key);— assigns the matching queue, if found.}— closes theif.// what if there's no matching rule at all?— if a Case'sPriority/Typecombination has no configured rule,Assigned_Queue__csimply stays blank — the Case silently falls through with no queue at all.}— closes the loop.
Adding a fallback queue
private static final String DEFAULT_QUEUE = 'General Support';
for (Case c : newCases) {
String key = c.Priority + '|' + c.Type;
if (queueByPriorityAndType.containsKey(key)) {
c.Assigned_Queue__c = queueByPriorityAndType.get(key);
} else {
c.Assigned_Queue__c = DEFAULT_QUEUE;
}
}
private static final String DEFAULT_QUEUE = 'General Support';— this is Module 26's named-constant refactor, applied from the start rather than as an afterthought.- (blank line)
for (Case c : newCases) {— loops over the new Cases.String key = c.Priority + '|' + c.Type;— the composite key.if (queueByPriorityAndType.containsKey(key)) {— the matched case.c.Assigned_Queue__c = queueByPriorityAndType.get(key);— assigns the configured queue.} else {— the unmatched case.c.Assigned_Queue__c = DEFAULT_QUEUE;— every Case gets some queue assignment, even one that hasn't been explicitly configured yet.}— closes theif/else.}— closes the loop.
Why a fallback beats silence
A Case with a blank Assigned_Queue__c is effectively invisible to whichever process routes Cases to support agents — it could sit unassigned indefinitely with nobody responsible for noticing. Routing it to a general fallback queue, even an imperfect match, guarantees a human eventually sees it — a genuinely better failure mode than a silent gap in the automation.
Exercise
Add a fallback assignment to this loop: if the key isn't in the lookup, set c.Assigned_Queue__c to 'General Support'.
Show hint
Add an else branch to the existing if.
Automate Case Routing Quiz
My Notes
Log in to keep private notes on this lesson.
Questions about this lesson
No questions yet — be the first to ask.
Log in to ask a question about this lesson.
Summary
The previous lesson routes Cases that match a configured rule — this lesson handles the case (no pun intended) where no rule matches at all, with a sensible fallback rather than silence.