If Statement In Salesforce

by | Jun 26, 2022 | Salesforce

Home » Salesforce » If Statement In Salesforce


IF is a conditional statement that controls the flow of our program. It can give us TRUE or FALSE as an output.

If Statements In Salesforce

IF statements work in Salesforce in the same way as in Java or any other programming language. It is used to evaluate the criteria.

If the condition is true, it will execute the code written in that block and if it’s not true, it will go to the next else if block and execute the code when else if the condition is true. If none of the Boolean conditions are true, it will execute the block of code written in else.


public class IfExample{
public static void ifStateExam(){
//when first condition is true
}else if(boolean_condition){
//when above condition is true
//when none of the condition is true



1. String day = ‘Tuesday’;

if(day == 'Monday' || day == 'Tuesday' || day == 'Wednesday' || day == 'Thursday' || day == 'Friday'){
System.debug('Office Time');
System.debug('Party Time');


OUTPUT: Office Time

2. String today = ‘Saturday’;

if(today == 'Monday' || today == 'Tuesday' || today == 'Wednesday' ||today == 'Thursday' || today == 'Friday'){
System.debug('Office Time');
}else if (today == ‘Saturday’){
System.debug('Go for movie');
System.debug('Go for party');


OUTPUT: Go for movie

3. Double total = 95.5;

if(total >= 90){
System.debug('You got A grade');
}else if(total >= 70 && total < 90){
System.debug('You got B grade');
}else if(total >= 60 && total < 70){
System.debug('You got C grade');
}else if(total >= 50 && total < 60){
System.debug('You got D grade');
System.debug('You got E grade');


OUTPUT: You got A grade


Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.