+ Start a Discussion
Matthew BathersbyMatthew Bathersby 

Visualforce Data Loss on ReRender

I have a simple controller that is designed to act as a time. As so:

public class timerController {

    public static dateTime startTime {get;set;}
    public static dateTime stopTime {get;set;}
    public static void startTimer(){

        startTime = system.now();

    public static void stopTimer(){
        stopTime = system.now();



Each method is tied to a button ('Start Timer' and 'Stop Timer'). When I run the startTimer method, I can see the startTime value in my debug.
When I run the stopTimer method, I can see the stopTime value in my debug, but the startTime has been reset to null.

Why is the startTime value not being maintained in the state? I know I must be missing something small, but I can't for the life of me spot it.

Any suggestions would be greatly appreciated.

you just have to remove 'static' keyword from your code.

If this post helped you, please mark it as "Best Answer"; otherwise reply with your doubts.
George thomasGeorge thomas

Http protocola are stateless and salesforce introduced view state to maintain the http elemts data. But there are 2 exception in that case, the variables which are static and transient doesn't maintain the state on the page. Please dont use static ,transient if you want your page to retain the variable values. Thanks!!
Matthew BathersbyMatthew Bathersby
Thanks folks. I knew it would be something simple. This did the trick nicely!