Sub topic 5
Checkbox: true or false data
This chapter assumes you know how to create a custom field in Object Manager and understand the difference between standard and custom fields. It covers the Checkbox field type: what it stores, how it behaves, and where it causes problems.
What a Checkbox stores
A Checkbox field holds one of two values: checked (true) or unchecked (false). It has no third state. A Checkbox field is never null. If a record has no value for it, Salesforce treats the field as false.
This is the main difference from other types. A Text or Date field can be blank, which means "unknown". A Checkbox cannot be blank, so "no" and "not answered" look the same.
Creating a Checkbox
When you create the field, you choose a default value of Checked or Unchecked. This default is required for the type. It applies to new records and to existing records at creation time, which is why existing records show as unchecked when you add a new Checkbox.
Because a Checkbox always has a value, the "Required" attribute does not apply to it. A Checkbox cannot be forced to be checked through that setting. Use a validation rule if a box must be checked before saving.
AND(Requires_Approval__c, NOT(Approved__c))This validation rule formula blocks a save when approval is required but missing. It uses the field names directly, since a Checkbox is already a Boolean.
Using Checkbox values in formulas and code
In formulas, a Checkbox is a Boolean. Compare it directly, without = TRUE.
IF(IsPriority__c, "Call today", "Normal queue")In Apex, the field maps to the Boolean type. In SOQL, filter with true or false.
List<Account> priority = [
SELECT Id, Name
FROM Account
WHERE IsPriority__c = true
];
System.debug(priority.size());When Checkbox is the wrong choice
A Checkbox suits a real yes/no fact, such as "Is Active" or "Opted Out of Email". It fits poorly when the answer may be unknown or may later need more options.
| Situation | Better choice |
|---|---|
| Yes, No, and Unknown are all meaningful | Picklist with three values |
| The status may gain more states later | Picklist |
| Several independent flags on one concept | Separate Checkbox fields, or a multi-select picklist |
| You need to know when or why it changed | Checkbox plus a date field, or field history tracking |
Exercise
A team wants a field recording whether a customer agreed to a survey. Some customers were never asked. Why is a Checkbox a poor fit, and what would you use?
Show answer
A Checkbox cannot be blank, so customers who were never asked appear identical to those who declined. Use a picklist with values such as Agreed, Declined, and Not Asked.