Salesforce Apex Tutorial – Chapter 8: Apex Constants

Salesforce Apex Tutorial – Chapter 8: Apex Constants

On October 19, 2021, Posted by , In Salesforce Apex Tutorial, With Comments Off on Salesforce Apex Tutorial – Chapter 8: Apex Constants

Read the previous one Salesforce Apex Tutorial – Chapter 7: Apex Arrays and next one.

Apex constants are variables that hold their values after being initialized once. A constant value can not be changed once initialized or assigned a value. The final keyword is used to define constants.

The final keyword indicates that the variable can only be initialized once, either directly, or with a static initializer method.

For example,

public class myCls {
static final Integer PRIVATE_INT_CONST = 200;
static final Integer PRIVATE_INT_CONST2;
public static Integer calculate() {
return 2 + 7;
}
static {
PRIVATE_INT_CONST2 = calculate();
}
}

Comments are closed.