Apex · Salesforce

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;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s