ApexSensei

Drills › Think in classes

Build queue labels with parameters

Think in classes · Beginner · 10 min · Runs in your Salesforce Developer org · Free

Scenario. A support dashboard needs consistent queue labels for any owner and workload count.

Pass different owner names and Case counts into one reusable method.

What you will learn

Parameters make one method reusable. Each call passes its own values, in the same order and types as the declaration.

String greet(String name, Integer visits) {
    return name + ' :: visits ' + visits;
}

greet('Maya', 3) returns Maya :: visits 3.

Gotcha. Parameter names exist only inside their method. The caller can pass any variable or value.

The task

Finish one method that builds a queue label from an owner name and a Case count, then call it three times.

Examples:

  • owner Maya, count 3 → Maya queue: Maya :: cases 3
  • owner Noah, count 8 → Noah queue: Noah :: cases 8
  • owner Priya, count 0 → Priya queue: Priya :: cases 0

Requirements:

  1. Make buildQueueLabel return the owner name, :: cases , then the count.
  2. Build the label only from the two parameters, not from fixed names or numbers.
  3. Call the same method for Maya, Noah and Priya. Print Maya queue:, Noah queue: and Priya queue:, each followed by the result.
  4. The checks also call buildQueueLabel with other names and counts, so it must work for any input.

Starter code

class QueueLabeler {
    public String buildQueueLabel(String ownerName, Integer caseCount) {
        return '';
    }
}

QueueLabeler labeler = new QueueLabeler();

When it passes

One method builds all three labels, including a zero count, and works for any owner and count the checks pass in.

Try this drill free

You write the Apex yourself. ApexSensei runs it and tells you what passed and what did not.

‹ Build a Case summary class · Return a value and record work ›