Welcome to my blog

I have been working with Salesforce for quite a while, so don’t hesitate to contact me if you have any questions or want some advice.

s f

Subscribe
Follow Us
h

Variables in Apex

 . Apex  . Variables in Apex
Learn How to Declare Null Variables & Initial Value Variables in Apex

Variables in Apex

Learn How to Declare Null Variables & Initial Value Variables in Apex

As already we discussed about Apex language that is a strongly typed language so we have to declare all variable before they are referenced in Apex coding. As general when we declare variables we have to declare data type followed by variable name.  

For example :-

 Integer i; (Integer = Data Type, i = variable name).

Local variables are declared with Java-style syntax. As with Java, multiple variables can be declared and initialized in a single statement.

Local variables are declared with Java-style syntax.

For example:-

            Integer i = 0;

As with Java, multiple variables can be declared and initialized in a single statement, using comma separation.

For example:-

            Integer i, j, k;

Declaring null Variables and Initial Values:-

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;

Post a Comment