49

I am just wondering what could be differences between ISBLANK and ISNULL. I found following link http://shivasoft.in/blog/salesforce/salesforce-interview-questions-%E2%80%93-part-2/

But I think ISNULL works on text fields. What you guys think? Which one is to be used?

3 Answers 3

64

Per the documentation, ISBLANK() should be used instead of the legacy ISNULL(). The biggest difference having to do with text fields.

Use ISBLANK instead of ISNULL in new formulas. ISBLANK has the same functionality as ISNULL, but also supports text fields. Salesforce will continue to support ISNULL, so you do not need to change any existing formulas.

This is further explained by,

Text fields are never null, so using ISNULL() with a text field always returns false. For example, the formula field IF(ISNULL(new__c) 1, 0) is always zero regardless of the value in the New field. For text fields, use the ISBLANK function instead.

1
  • 1
    I tested ISNULL() with number fields. It always returns false regardless of the value. May 31, 2021 at 23:37
15

I think it's likely to depend on the scenario in question, but you should be aware that ISNULL does not work the same way as ISBLANK for text.

When dealing with text and lookup fields, a blank value in the field yields true for ISBLANK() but false for ISNULL()—even if you set a text field to null in apex it is still treated as blank (i.e. not null) in the formula.

Essentially the system works the same way as you'd expect in a programming language: an empty string is not the same as a null value, it is still an instance of a string.

1

The link to the Blog in the original question on Salesforce Interview Questions is broken, so we don't know the context. For that reason I'm going to add an update that goes beyond the answers provided.

If used in Apex (not a formula field), isEmpty(inPutString) covers both isBlank(inPutString) and isNull(inPutString)`. See the following references in the Apex Documentation for the String Class.

isBlank(inputString) Returns true if the specified String is white space, empty (''), or null; otherwise, > returns false.

isEmpty(inputString) Returns true if the specified String is empty ('') or null; otherwise, returns false.

isNull() no longer applies to sets, lists, or maps. Instead, IsEmpty() is used for sets, lists or maps with zero elements. You'll only see isNull used in Formulas. In checking the documentation, you'll find the following:

IMPORTANT Use ISBLANK instead of ISNULL in new formulas. ISBLANK has the same functionality as ISNULL, but also supports text fields. Salesforce will continue to support ISNULL, so you do not need to change any existing formulas.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .