+ Start a Discussion

Extending the scope of static variable

I have a VF page and an extension class to extend the standard controller. I need to have a global variable in the apex class which keeps incrementing by 1 each time a particular function is accessed. As the scope of 'static' is limited to a request, i'm not able to track the count. Can anybody help?
Hi Oxene,

i thing here you can use the custom object and you can save the counter in object and when function is accessed you increment the counter and update the object again.


if you want to work only on page level then you can use this technique:

class Scope{
public Integer counter = 0;

public Integer getCOunter(){
return counter;

public Scope getData(){
counter ++;
return <object of scope or whatever u are returning>

Then in VF page u can simply use {!counter}
no need of use static variable, as it will directly increase the counter variable and finally u will get the number of functions called.


Thanks Jitendra...