How does Visual force pages and Apex Controllers maintain their view states i.e. are Apex Controller Classes single instance classes or are the multi instance classes.

If I have a situation where I am logged in to Salesforce from 2 machines using same credentials and I am calling a function to set value of a global variable from both the machines then whether both the calls from different machines will over-write each other's values or both the machines will have different instances of same controller.

How does this view state stuff works in different cases like : 1. same user logged into 2 or more different machines simultaneously.

1 Answer 1


If you inspect a VF page in your web browser and search for "viewstate" you should see something simmilar to the following:

<input type="hidden" 

Note that the value attribute is going to be extremely long.

When you load a VF page SFDC essentially sends a copy of the class with the page. When you send a request back this information is sent back to SF with the request which let's it know what the state of the page was at the time of the request. This means that the controller is actually re-instantiate with each request, it's just pre-populatd with the data provided by the view state input so that it can continue from where it left off.

Because of this, each individual request/browser maintains it's own state; regardless of the credentials used or how many copies of the page are being accessed at a time.

Worth noting is that there is a limit to how much information you can store in a view state.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .