Wednesday 29 August 2012

Null Variables - Apex

If you declare a variable and don't initialize it with a value, it will be null. In essence, null means the absence of a value. You can also assign null to any variable declared with a primitive type. For example, both of these statements result in a variable set to null:
Boolean x = null;
Decimal d;
Many instance methods on the data type will fail if the variable is null. In this example, the second statement generates a compilation error.
Decimal d;
d.addDays(2);
This results in the following error: line 2, column 1: Method does not exist or incorrect signature: [Decimal].addDays(Integer).

2 comments: