function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
liron169liron169 

Static variables in controller

Hi,
I have controller that I want to define most of the logic inside as 'ReadOnly'.
Since I cannot set this attribute to the constructor, I create webservice function 'ReadOnly' and call it from the constructor to set all the require data for the page.

However, it's also require from me to change most of the variable in the controller to be 'static' (otherwise the webservice function cannot set those variable.

The questions is what impact such change might have (change the variable to 'Static')?
Can it cause any harm in the page?
And whether this is correct from programming prespective and SF best practice?
Vinita_SFDCVinita_SFDC
Hello,

All static member variables in a class are initialized before any object of the class is created. This includes any static initialization code blocks. All of these are run in the order in which they appear in the class.

A static initialization code block is only initialized once on the first use of the class.

Refer following thread for a better understanding with example:

http://salesforce.stackexchange.com/questions/8568/when-should-a-static-intializer-be-used