Build a Case summary class
Think in classes · Beginner · 10 min · Runs in your Salesforce Developer org · Free
Scenario. A support tool needs a reusable in-memory summary before any Case record is saved.
Write a small class, create separate Case summary objects, and call a method on each one.
What you will learn
A class groups data (fields) with behavior (methods). Create each object with new, set its fields, then call a method on it.
Ticket item = new Ticket();
item.subject = 'Login';
String text = item.describe();
Each object keeps its own field values.
Gotcha. Declaring a class does not create an object. You still need new.
The task
Create three CaseSummary objects and print the summary each one returns.
Examples:
- subject
Login issue, statusNew→First: Login issue :: New - subject
Refund request, statusEscalated→Second: Refund request :: Escalated - blank subject, status
New→Empty subject: (no subject) :: New
Requirements:
- Finish
describe()so it returns the subject,::, then the status. - When the subject is blank, use
(no subject)in its place. - Create a separate object for each of the three Cases in the examples.
- Print
First:,Second:andEmpty subject:, each followed by that object'sdescribe()result.
Starter code
class CaseSummary {
public String subject;
public String status;
public String describe() {
return '';
}
}
CaseSummary first = new CaseSummary();
first.subject = 'Login issue';
first.status = 'New';
When it passes
Three separate objects return their own summaries, and a blank subject shows `(no subject)`.
You write the Apex yourself. ApexSensei runs it and tells you what passed and what did not.