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
JuanBessJuanBess 

null values instead of empty values

Hi, I'm working on a native force.com application. Since this weekend our code start failing in some orgs.

The problem seems to be the assignment of '' (empty value, or just spaces). The strange thing is that is failing in some orgs, and in some of the is working fine. All of them are in the winter release.

 

I tried this in my orgs:

 

Account a = new Account();
a.name = '';
system.debug('\n\n================\n' + a + '\n==========================\n\n');

 

 

In some of the the result is:

 

================
Account:{Name=null}
==========================

 

 

And in some others:

 

================
Account:{Name=}
==========================

 

 

I don't know if they have changed to assign null instead of '', but at least seems to be an issue of consistence between different salesforce instances.

Anyone had the same issue?

Juan.

Ispita_NavatarIspita_Navatar

After the winter 11 , release even we have come across issue related to null handling. I think salesforce will fix it once they are informed, but in the interim we have user a condition based on OR operation for (null and '') for ex. if(Acc=null OR Acc='') and released an upgrade.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.

JuanBessJuanBess

Thanks for the response. I had to had the null check into my conditions and change a little bit some classes, and then release a new package.

I wanna know if someone got an answer from salesforce if they plan to change/fix this, or they will continue assigning null values automatically?

J.

sfdcfoxsfdcfox

I've actually occasionally noticed this Pre-11 as well. Sometimes, I'd have an assignment as follows:

 

 

String s = '';
for(String z:someMap.keySet())
  s += z + '-';

And on occasion, this would result in either a "string is null" error or, more likely, a resulting string such as "null-firstkey-secondkey-".

 

 

I'm not sure what causes this to happen, but it's safer to always check versus null, and always assign null, and not attempt string concatenation against a null string, etc. Virtually every piece of code I've written in the past few years has used the "if(aString <> null && aString <> '')" (or the inverse) syntax for this reason. The above loop, for example, would be best as:

 

 

String s = null;
for(String z:someMap.keySet())
  if(s==null || s=='')
    s = z + '-';
  else
    s += z + '-';

 

 

Pradeep_NavatarPradeep_Navatar

Sometimes Field values takes null and '' in different instances so you have to check as in the sample given below :

 

if(a.name == '' || a.name == null)                                

 

Hope this helps.