Monday, October 20, 2014

No NULL exception? What the Hell???

Just a little end of the day rant about one of my least favorite software packages, Salesforce.

If I do something like this, shouldn't there be a NULL exception?

integer bar = null;
integer foo = 1;
foo = bar + foo;


Absolutely.  And Salesforce's APEX language does indeed raise a NULL Exception.  However, a little different flavor of that will not raise an exception.

Say for example you have an integer field called bar__c in the standard Salesforce object Lead.  You have a piece of code that pulls that object's record into memory; like...

Lead wrkLead = [select ID, bar__c from lead where status='Lock' limit 1];


So, shouldn't there be a NULL exception here?

integer foo = 1;
foo = wrkLead.bar__c + foo;


Well, I would think so, but nope.  APEX just keeps on chugging.  Watch out for this one.  If your data field could ever be NULL, code for it!

No comments:

Post a Comment