ApexSensei

Drills Apex basics

Switch on Case status

switch on compares one value with a list of when branches and runs the first match.

Your task

Fill in routeFor so it uses switch on status to pick an action, then run the provided debug lines.

String routeFor(String status) {
    String action = null;
    return action;
}

Case caseRecord = new Case(Status = 'New');
System.debug('New action: ' + routeFor(caseRecord.Status));

caseRecord.Status = 'Working';
System.debug('Working action: ' + routeFor(caseRecord.Status));

caseRecord.Status = 'new';
System.debug('Lowercase action: ' + routeFor(caseRecord.Status));

Requirements

  1. switch on status should be present
  2. when else should be present
  3. New action: Assign should be printed
  4. Working action: Continue should be printed
  5. Lowercase action: Review should be printed
  6. routeFor('Escalated') should be Review
  7. routeFor('Working') should be Continue

Sign in to open this drill