Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

Class Variables

To declare a variable, specify the following:
  • Optional: Modifiers, such as public or final, as well as static.
  • Required: The data type of the variable, such as String or Boolean.
  • Required: The name of the variable.
  • Optional: The value of the variable.
Use the following syntax when defining a variable:
1[public | private | protected | global] [final] [static] data_type variable_name 
2[= value]
For example:
1private static final Integer MY_INT; 
2      private final Integer i = 1;

Versioned Behavior Changes

In API version 50.0 and later, scope and accessibility rules are enforced on Apex variables, methods, inner classes, and interfaces that are annotated with @namespaceAccessible. For accessibility considerations, see NamespaceAccessible Annotation. For more information on namespace-based visibility, see Namespace-Based Visibility for Apex Classes in Second-Generation Packages.