Salesforce ISNULL Function

In this Salesforce tutorial, we will learn about the Salesforce ISNULL function execution. We will also discuss its use cases, syntax, and practical examples. The ISNULL function is executable in the formulas and validation rules of Salesforce Lightning and Salesforce Classic.

What is ISNULL function in Salesforce

In Salesforce, the ISNULL function determines if an expression has a value and returns TRUE if it does not. If it contains a value, this function returns FALSE. This function is primarily used within formula fields, validation rules, and workflow rules to evaluate whether a particular field or expression holds any value.

Syntax of ISNULL function in Salesforce

The syntax of the ISNULL function is defined in the following way.

ISNULL(expression)

The expression in the above syntax is the field or formula expression that you want to check for being null.

Considerations:

There are some considerations that we must follow while using the ISNULL function in Salesforce.

  • If you are using the ISNULL function with the Text fields then it will return False because Text fields are never null. For text fields, use the ISBLANK function instead.
  •  Using this function with a multi-select picklist field in s-controls, buttons, and email templates always returns false because Multi-select picklist fields are never null in these scenarios.
  • Empty date and date/time fields always return true when referenced in ISNULL functions.
  • Use ISBLANK instead of ISNULL function for date/time fields.
  • While referencing a number, percent, or currency field in an ISNULL function choose Treat blank fields as blanks for the formula.
  • In the new formulas use ISBLANK instead of ISNULL. ISBLANK has the same functionality as ISNULL but also supports text fields.
  • When using a validation rule to ensure that a number field contains a specific value, use the ISNULL function to include fields that do not contain any value.

Use ISNULL function in Salesforce Lightning

In this example, we will create a custom formula using the ISNULL function, where the custom formula field will return the amount of discount based on the amount field of the opportunity.

The custom formula field will calculate a discount based on the amount field of the opportunity but only if the custom field Minimum Discount is populated. Otherwise, the discount should be zero.

See also  OR Function in Salesforce

To create a custom formula field using the ISNULL function in Salesforce Lightning, follow the below steps.

1. To navigate on the Setup of Salesforce lightning, click on the settings icon, and from the options in the dropdown select Setup.

Create a custom formula field with ISNULL function

2. On the Setup page of Salesforce Lightning click on the Object Manager tab.

3. In the Object Manager tab, select the Opportunity object, else select the object in which you have to create a custom formula field.

4. In the setup window of the Opportunity object click on the Fields & Relationships on the left sidebar then in the next window click on the New button.

Salesforce Lightning ISNULL function

5. In this window, select the Field Type as Formula and click on the Next button.

Salesforce Lightning ISNULL function use case

6. In this step, we will define the output of the custom formula field by entering the details below.

  • In the Field Label, enter the name of the field output. In this example, I have named it Applied Discount, and the Field Name will be auto-filled according to the entered Field Label.
  • In the Formula Return type select the field return type as Currency or Number then click on the Next button.

7. In this step, we will enter the below formula in the formula editor according to the condition explained above.

IIF(ISNULL( Minimum_Discount__c ), 0, Amount * 0.1)

The conditions that we have applied in the above formula are as follows:

  • Minimum Discount is a custom field on the Opportunity object.
  • Amount is a standard field on the Opportunity object, representing the total amount of the opportunity.
  • The formula checks if the custom field “Minimum Discount” is null using ISNULL( Eligible_for_discount__c ).
  • If the custom field is null the output will be zero else the formula calculates a 10% discount on the Amount.

8. After entering the formula, click on the button Check Syntax to validate the formula and check the errors in the formula.

Salesforce Lightning ISNULL function validate formula

9. Now we have to select the profiles who can view this custom field. In this example, I have activated the Visible checkbox to give access to all profiles, and after this click on the Next button.

10. At last activate the checkboxes of the page layouts to make this field visible on the page layouts and this field will be visible in the activated page layouts. Now I will show you the formula field output in the Opportunity record where I will leave the field Minimum Discount as null.

Salesforce Lightning ISNULL function Output field

As we can see in the above image the field Applied Discount returns “0” because according to the condition in the formula, the formula field (Applied Discount) will be 0 when the Minimum Discount is NULL.

See also  ABS() Function in Salesforce | Calculate absolute value in Salesforce

In this way, we have successfully executed the ISNULL function in Salesforce Lightning by creating a validation rule using the ISNULL function.

Use ISNULL function in Salesforce Classic

In this example, we will create a Formula field using the ISNULL function in the Case object.

This formula field will help to track the Case status of the Case record. We will define a condition in this formula field where it will return the output “ongoing” when the End Time field is null.

With the help of this, we can track which Cases are resolved and the one which is still ongoing on.

To create a custom formula field in Salesforce Classic, follow the steps below.

1. On the Home page of Salesforce Classic, click on the Setup tab.

2. In the Setup of Classic, go to the Build section in the left sidebar and select Customize -> Cases -> Fields.

3. In the Fields setup scroll down to the section Custom Fields and Relationships and click on the New button.

Salesforce Classic ISNULL function

4. In the Field Type select the option Formula and click on the Next button.

Salesforce Classic ISNULL function custom Formula field

5. In this window, we will define the Formula field output by entering the below fields.

  • Enter the output name in the Field Label and in this example, I have named it as Case Status according to the scenario.
  • The Field Name will be auto-filled according to the entered Field Label.
  • In the Formula Return type select the option Text, then click on the Next button.
Salesforce Classic Custom Formula field with ISNULL function

6. In this step, we will enter the below formula in the Formula editor according to the scenario explained in the beginning.

IF(ISNULL(End_Time__c), "Ongoing", "Completed"), "Ongoing", "Completed")

In the above formula, we have applied the logic in the following way.

  • With IF conditional IF(ISNULL(End_Time__c), will check whether the field End Time is Null.
  • If the field End Date is Null, it will return Ongoing.
  • If the field End Date is not null, the output will be completed.
See also  EXP() Function in Salesforce | Calculate exponential value in Salesforce

7. After entering the Formula click on the button Check Syntax to validate the formula and check errors. On the successful validation click on the Next button.

Salesforce Classic ISNULL Function formula validation

8. In this step, we have to select the profiles that can have access to view this field. To select the profiles, activate the checkboxes adjacent to profile names.

If you have to select all profiles then click on the Visible checkbox then click on the Next button.

Salesforce Classic Custom Formula field using ISNULL function

9. Activate the Page Layouts to make this formula field visible on the Page layouts and this field will be visible on the activated page layouts only. At last click on the Save button.

As we click on the Save button the formula field that we have created using the ISNULL function, will be saved in the Cases object.

Now to check the output of the formula field, we will open a Case record and there we will leave the End time field as null.

Salesforce Classic ISNULL function custom Formula field Output

As we can see in the above image the field output is Ongoing because according to the condition applied in the formula if the field End time is null the formula field Case Status will return Ongoing.

In this way, we have successfully executed the ISNULL function in Salesforce Classic with the help of a custom formula field.

Conclusion

In this Salesforce tutorial, we have learned about the conditional function ISNULL with the help of practical examples where we created custom formula fields in Salesforce Lightning and Salesforce Classic with a couple of scenarios.

Along with this we also learned about the use of ISNULL in Salesforce and later we discussed the syntax and the considerations of the ISNULL function.

You may like to read: