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?
}
If a Case's Priority/Type combination has no configured rule (say, a new Type value was added but nobody created a matching routing rule yet), Assigned_Queue__c simply stays blank — the Case silently falls through with no queue at all.
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;
}
}
This is Module 26's named-constant refactor, applied from the start rather than as an afterthought — every Case gets some queue assignment, even one that hasn't been explicitly configured yet.
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.