Boolean
By the end of this lesson, you'll be able to:
- Explain what a Boolean represents
- Declare and use a Boolean variable
- Use a Boolean to represent a real business condition
Prerequisites: "Text: String"
Only two possible values
Boolean isActive = true;
Boolean hasDiscount = false;
That's the entire type — no in-between, no "maybe." A Boolean is often the result of asking a question: "is this customer active?", "does this order qualify for a discount?"
A real business example: Healthcare
Boolean isInsured = true;
Boolean requiresFollowUp = false;
A patient record system constantly deals in yes/no facts like these — and Module "Making Decisions" (right after this one) is entirely about acting on Booleans like these with if statements.
Common mistakes
- Writing
if (isActive == true)instead ofif (isActive). Both work, but the second is the idiomatic, cleaner Apex style — a Boolean variable already is the true/false answer, no comparison needed. - Naming Booleans ambiguously.
flagorstatustells you nothing;isActiveorhasDiscounttells you exactly whattruemeans.
Exercise
Declare a Boolean called isEligibleForDiscount and set it to true. Debug it.
Show hint
This is as simple as it looks: Boolean isEligibleForDiscount = true;
Boolean Quiz
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
A Boolean holds exactly one of two values: true or false. Despite being the simplest type in Apex, Booleans are what every business decision in your code ultimately boils down to.