Booleans
Not Started

Katy Perry once famously said, “you’re yes then you’re no” in her 2008 hit “Hot N Cold”. I’m convinced she was talking about Booleans.

Some questions can only be answered with “yes” or “no”. Did I lock the front door? Did I leave the stove on? Have I ever been to Iceland? That’s what a Boolean represents in Apex. Instead of yes, we have true. Instead of no, we have false. They’re just like the checkbox field on sObjects.

In this context, true and false are keywords provided by Apex.

Later, we’ll explore if conditions and see how Booleans are used to make decisions.

Boolean hasValidationPassed = true; Boolean doesUserExist = false; doesUserExist = true; Boolean isOpportunityClosed; isOpportunityClosed = true; Boolean didILeaveTheStoveOn; didILeaveTheStoveOn = false; Boolean canProcceed = true;

As I said before, naming variables can be challenging. For Booleans, I'd suggest prefixing them with words like is, has, does, are, did or similiar words to make it clear that the variable is a Boolean. This will be useful when a variable is referenced later in the code.

Easy! You're killin' it.

Challenge

You're asked to keep track of whether of not a user is active in Salesforce. To do that, create a Boolean called isUserActive and set it to true.