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

Randomly loosing controller state

I have a fairly complex Visual Force page with associated controller. A couple of support pages reference the same controller. As I redirect to the support pages, and back again, generally everything is fine. But every so often, I get a crash. I tracked this down to the controller losing state. From the debug logs I can see that its constructor is being loaded again in these cases.


It seems worst when network connectivity is poor, but otherwise I can't identify any reason as to why the controller would occasionally lose state. There is no consistent repro. Does anyone have any ideas as to what might the root issue might be?


When you redirect to the support pages your pagereference setRedirect state true or false. If you have set setRedirect true reloaded the constructer.




I'm simply returning a page reference in response to an action method call. I'm aware of the issues around explicit redirects with the setRedirect parameter.


As I mentioned, I'd random. 95% + of the time the page transitions work just fine. But every so often, the controller is reset.


Update: I *think* I got to the bottom of this. Here's the detail in case anyone else encounters the same type of issue.


I have a fair bit of javascript code, and some of this calls into SF via Actionfunctions. In one case, the action function being called was void as I wanted the user to stay on the same page. However, I didn't specify and rerender targets, and VisualForce was refreshing the page and hence re-instantiating the controller.