Activity Forums Salesforce® Discussions What is the difference between empty and null in Salesforce?

  • Adam

    Member
    November 1, 2018 at 10:46 pm

    Another one to test us on 🙂

    From the outside the difference can appear very slight.  But to code that is running, it could mean very different outcomes!

    In coding (once again I am assuming it is in the context of APEX), something could be NULL because it doesn't exist or hasn't been instanciated (ie it hasn't been created/setup).

    Where as empty has two possible outcomes/possibilities.  It could mean that it is a string/text (as an empty) that is nothing.  For example ''.  There is nothing in between the ' and the '.  But the code has allocated memory to the variable, even if there isn't any actual text stored.  Additionally, it could also mean NULL (see above).

    The Salesforce documentation also makes note of 'blank' which essentially has three possible outcomes: that whitespace is stored in the field, that '' is stored in the field, or NULL.  So when using forumals in Salesforce, I always try to use ISBLANK(), as it is the most 'inclusive' of the three functions.

  • William

    Member
    March 6, 2019 at 7:24 am

    for the outside world, the difference could be negligible but it means a lot for the developers because it always results in different outcomes. Null is nothing but the default value that is assigned to any variable, not initialized yet. At the same time, an empty string is blank and it will return the length as zero because the string doesn’t contain anything.

  • Hariom Chaudhary

    Member
    August 12, 2019 at 12:27 pm

    IS Blank:

    Its a function which validates whether the field has some value or not. Value can be some digit( 0-9), alphabet( a-z A-Z), special character ( %,$,--). If your  field contains any of them then this function will return  false. If it contains Blank (" ") or no value then it will return True.

    IS NULL:

    This function will consider Blank (" ") as some value. And if your field has Blank(" ") then it will return false considering 'Blank' also as some value.

    For more information visit:

    https://developer.salesforce.com/forums/?id=906F00000008nV0IAI

  • Ashutosh

    Member
    September 13, 2019 at 11:08 am

    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.

Log In to reply.

Popular Salesforce Blogs