2

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.

6

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" 
    id="com.salesforce.visualforce.ViewState" 
    name="com.salesforce.visualforce.ViewState" 
    value="...">

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.