Static Variable in Apex

A class static variable is a global variable that is associated with a particular class.

Multi-threaded application take care of synchronize access of static variables, to avoid race condition.

Static variable in Apex have execution context scope and lifetime, which means- static variables can only be accessed from within the execution context in which they are created, and are deleted when the execution context completes.

 Static variable don’t persist information between execution contexts. They can’t be used to keep track of the overall execution of your application or to cache data or objects for use while your application is running.

Apex does not support application or session variable at all. Anything you want to persist must be stored in database object or custom settings.

One thought on “Static Variable in Apex

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