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
Prakash@SFDCPrakash@SFDC 

unable to acess static variable in non static method

Hi,

 

I am facing a problem while accessing a static variable in non static method.

 

from a visulaforce pagewhen a button is clicked i am calling a remoteaction method which is static . in that method i am assigning the id of a perticular object to a static filed called agreementId.After this remoteaction method i am calling an action function which calls a non static method , in that method i need to use this static field agreementId . when i am printing this it is giving as null .

 

I tried to access this filed by using classname.filed still it didn't work .

 

Please let  me know how to access this field .

 

 

 

Bhawani SharmaBhawani Sharma
Static variable holds the state only for one request. Like if yiu set a static variable and use it across the classes, value will be maintained , but It will be reset in next request.
Prakash@SFDCPrakash@SFDC

Means there is no other way to maintain the same value for different requests .

Bhawani SharmaBhawani Sharma
You can use public variable. It won't reset.
Prakash@SFDCPrakash@SFDC

I can't use public variable in static method right ?

Bhawani SharmaBhawani Sharma
correct. So what you can do is, Hold the result of the remote function is Javascript and put it in some inputHiddedn field on Page. Next time you will perform any submit action, this will be get associated to your public property.