You need to sign in to do that
Don't have an account?
liron169
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?
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?
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