Beginner 10 min read

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 of if (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. flag or status tells you nothing; isActive or hasDiscount tells you exactly what true means.

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;

APEX

Boolean Quiz

1. How many possible values can a Boolean hold?

2. A well-named Boolean variable often starts with "is" or "has".

Log in to submit the quiz and save your score.

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.