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:
- Make
buildQueueLabelreturn the owner name,:: cases, then the count. - Build the label only from the two parameters, not from fixed names or numbers.
- Call the same method for Maya, Noah and Priya. Print
Maya queue:,Noah queue:andPriya queue:, each followed by the result. - The checks also call
buildQueueLabelwith 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.
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 ›