function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SirTravSirTrav 

Null string in if statement

I have an input field on a visualforce page called y1supportPackage.  on the extension I have this field in an if statement.  I have tried this statement two different ways.

1. if(string.isNotBlank(y1supportPackage)) { code here}

2. if(y1supportPackage != null){code here}

 

What is throwing me off is that it is saying the field is not blank when it is.  I have added 2 debugs just above the if statement.  So here is what it looks like right now

system.debug(logginglevel.info, '*****y1supportPackage='+y1supportPackage);
        system.debug(logginglevel.info, '*****string.isNotBlank(y1supportPackage)='+string.isNotBlank(y1supportPackage));
        if(string.isNotBlank(y1supportPackage)) {

 Here is what my debug log is saying:

18:38:00.227 (227910000)|USER_DEBUG|[1333]|INFO|*****y1supportPackage=null
18:38:00.227 (227918000)|SYSTEM_METHOD_EXIT|[1333]|System.debug(APEX_OBJECT, ANY)
18:38:00.227 (227934000)|METHOD_ENTRY|[1334]|01pK0000000AbBG|addProductsExt.__sfdc_y1supportPackage()
18:38:00.227 (227951000)|METHOD_EXIT|[1334]|01pK0000000AbBG|addProductsExt.__sfdc_y1supportPackage()
18:38:00.227 (227969000)|SYSTEM_METHOD_ENTRY|[1334]|String.isNotBlank(String)
18:38:00.227 (227979000)|SYSTEM_METHOD_EXIT|[1334]|String.isNotBlank(String)
18:38:00.227 (227988000)|SYSTEM_METHOD_ENTRY|[1334]|String.valueOf(Object)
18:38:00.227 (227997000)|SYSTEM_METHOD_EXIT|[1334]|String.valueOf(Object)
18:38:00.228 (228008000)|SYSTEM_METHOD_ENTRY|[1334]|System.debug(APEX_OBJECT, ANY)
18:38:00.228 (228023000)|USER_DEBUG|[1334]|INFO|*****string.isNotBlank(y1supportPackage)=true
18:38:00.228 (228031000)|SYSTEM_METHOD_EXIT|[1334]|System.debug(APEX_OBJECT, ANY)
18:38:00.228 (228040000)|METHOD_ENTRY|[1335]|01pK0000000AbBG|addProductsExt.__sfdc_y1supportPackage()
18:38:00.228 (228056000)|METHOD_EXIT|[1335]|01pK0000000AbBG|addProductsExt.__sfdc_y1supportPackage()
18:38:00.228 (228066000)|SYSTEM_METHOD_ENTRY|[1335]|String.isNotBlank(String)
18:38:00.228 (228074000)|SYSTEM_METHOD_EXIT|[1335]|String.isNotBlank(String)
18:38:00.228 (228088000)|METHOD_ENTRY|[1336]|01pK0000000AbBG|addProductsExt.__sfdc_supportPackage()
18:38:00.228 (228103000)|METHOD_EXIT|[1336]|01pK0000000AbBG|addProductsExt.__sfdc_supportPackage()
18:38:00.228 (228113000)|SYSTEM_METHOD_ENTRY|[1336]|String.valueOf(Object)
18:38:00.228 (228120000)|SYSTEM_METHOD_EXIT|[1336]|String.valueOf(Object)
18:38:00.228 (228131000)|SYSTEM_METHOD_ENTRY|[1336]|System.debug(APEX_OBJECT, ANY)

 

You will notice that it says y1supportPackage=null and then the next line of code says that string.isNotBlank(y1supportPackage)=true.

 

What am I missing?  Why when the field is null is the if statement saying that it is not equal to null?

Best Answer chosen by Admin (Salesforce Developers) 
SirTravSirTrav

I figured out what it was doing.  The field is filled out with a select list and the first option I have it "" with a value of 'null'.  So null was not that the value was null but the text null.  Pretty dumb thing to do looking back on it.