Constants are variables whose values cannot be changed after they are initialized. In Apex, you can create a constant by using the final keyword.
// Declare a constant
final String ERROR_MESSAGE = 'An error has occurred.';
// The following line would cause a compile-time error:
// ERROR_MESSAGE = 'A new error.';
public class MyMath {
public static final Decimal PI = 3.14159;
}
Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.
Create account