Saturday, October 6, 2018

apex class variables

Variables are used to store values.In apex variables are case insensitive.
Declaring variable in apex includes following,

.Modifiers such as public/static etc are optional.
.you must define data type of variable and must give name to it.

Let see how to declare variables in salesforce..

Declaring integer,

Integer a;
Integer a=1; // Initializing

Declaring String,

string someName;
string someName='test'; // Initializing


boolean a=true;
boolean b=false;
Date someDateVariable;
Decimal someVariable;

In apex,We do have static variable.

Characterstics of static variable.
1) Initialize only once.
2) Does not occupy state.
3) Can be used only with outer class and are not used with inner class.

How to declare static variable?
public static boolean myVariable=true;

Advantages of using static variable:
You can avoid recursion by using static variable in helper class

No comments:

Post a Comment