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.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s