Comparison Operators in Practice
By the end of this lesson, you'll be able to:
- Recall the six comparison operators from Module 4
- Recognize that a comparison expression is the foundation of every decision Apex makes
- Write a comparison expression suited to a real business rule
Prerequisites: Module 5: "Enums"
A quick recap, with intent
You already know ==, !=, >, <, >=, and <= from Module 4. What's new here isn't the operators — it's the purpose. Every one of these produces a Boolean, and that Boolean is what an if statement (next lesson) actually reacts to.
Integer accountAge = 3;
Boolean isEstablished = accountAge >= 2;
isEstablished isn't just a value — it's a decision waiting to be acted on.
A real business example: Sales Automation
Decimal dealSize = 75000;
Boolean requiresExecutiveApproval = dealSize > 50000;
This single comparison encodes a real company policy: deals over R50,000 need executive sign-off. The next lesson turns this Boolean into actual branching behavior.
Exercise
Declare Integer daysSinceLastOrder = 45. Declare a Boolean called isAtRiskCustomer that's true if it's been more than 30 days. Debug it.
Show hint
daysSinceLastOrder > 30
Comparison Operators in Practice 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
Module 4 introduced the comparison operators as pure syntax; this lesson bridges into using them for their real purpose — driving decisions — which is exactly what the rest of this module builds on.