Advanced 30 min read

Test the Feature

By the end of this lesson, you'll be able to:

  • Manually verify a Case routes correctly when a matching rule exists
  • Verify the fallback queue applies when no rule matches
  • Verify a bulk insert of Cases with mixed Priority/Type routes each one correctly

Prerequisites: "Handle Errors Gracefully"

Verifying a matched rule

Case c = new Case(Subject = 'Login broken', Priority = 'High', Type = 'Problem');
insert c;

Case saved = [SELECT Assigned_Queue__c FROM Case WHERE Id = :c.Id];
System.debug('Assigned queue: ' + saved.Assigned_Queue__c);

Assuming a Case_Routing_Rule__mdt record exists for High/Problem, this confirms the routing lookup actually matched and assigned the configured queue — the closest available check to a real end-to-end verification before formal tests exist.

Verifying the fallback

Case c = new Case(Subject = 'Unusual request', Priority = 'Low', Type = 'Feature Request');
insert c;

Case saved = [SELECT Assigned_Queue__c FROM Case WHERE Id = :c.Id];
System.debug('Expected General Support, got: ' + saved.Assigned_Queue__c);

Choosing a Priority/Type combination deliberately unlikely to have a configured rule confirms Lesson 4's fallback logic actually fires.

Verifying a bulk batch with mixed values

List<Case> batch = new List<Case>{
    new Case(Subject = 'A', Priority = 'High', Type = 'Problem'),
    new Case(Subject = 'B', Priority = 'Low', Type = 'Question'),
    new Case(Subject = 'C', Priority = 'Medium', Type = 'Problem')
};
insert batch;

List<Case> saved = [SELECT Subject, Priority, Type, Assigned_Queue__c FROM Case WHERE Id IN :batch];
for (Case c : saved) {
    System.debug(c.Subject + ' (' + c.Priority + '/' + c.Type + '): ' + c.Assigned_Queue__c);
}

Exactly Module 27's "test with multiple records" lesson, applied here: a single-record test could never confirm the bulkified lookup (Lesson 3) correctly handles several different Priority/Type combinations within the same batch.

Exercise

Write an Execute Anonymous snippet inserting a Case with a null Type and confirming it still gets a queue assignment (the fallback).

Show hint

Insert with Priority set but Type left null, then re-query and check Assigned_Queue__c.

APEX

Test the Feature Quiz

1. Why does this lesson specifically test a bulk batch with mixed Priority/Type values?

Log in to submit the quiz and save your score.

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

Following Modules 26-27's established pattern, this lesson verifies the feature manually via Execute Anonymous — formal @isTest coverage is still ahead, in Module 31.