Search Here

Apex Boolean datatype

 In Apex, the Boolean data type is used to represent binary logic values, specifically either true or false. Booleans are commonly used for making decisions in conditional statements, controlling the flow of code, and storing simple true/false conditions. 


public class BooleanExample {

    public static void main() {

        Boolean isSunny = true;

        Boolean isRainy = false;


        System.debug('Is it sunny? ' + isSunny);

        System.debug('Is it rainy? ' + isRainy);


        if (isSunny) {

            System.debug('Enjoy the sunshine!');

        } else {

            System.debug('Don't forget your umbrella!');

        }

    }

}

We declare two Boolean variables: isSunny and isRainy. isSunny is set to true, indicating that it's sunny, while isRainy is set to false, indicating that it's not rainy.


We use System.debug() to print the values of isSunny and isRainy to the debug log.


We use an if statement to check the value of isSunny. If it's true, we print a message about enjoying the sunshine; otherwise, we provide a message about needing an umbrella.



Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.