• #51458
     Divya #708
    Forcetalks

    What is the difference between empty and null in Salesforce?

    Is there any difference between null and empty?

     

    #51487
    Salesforce | Adam Adam #542
    Forcetalks

    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.

    #58537
     William #13
    Forcetalks

    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.

    #60843
    Forcetalks

    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

    #62769
    Salesforce | Ashutosh Ashutosh #19
    Forcetalks

    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.

Viewing 5 posts - 1 through 5 (of 5 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2019 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?