Visualforce View State
In Visualforce, view state refers to the state of the page, including the state of its form data, component values, and controller state, that is transmitted to and from the server with each request. View state enables Visualforce pages to maintain stateful behavior similar to traditional web applications, where user inputs and interactions are preserved across multiple requests.
Steps to reduce the View State
- Use filters and pagination to reduce data that requires state.
- Declare an instance variable with a transient keyword if the variable is only useful for the current request. A transient variable isn’t included in the view state.
- Refine your SOQL calls to return only data that's relevant to the Visualforce page.
- Reduce the number of components that your page depends on.
- Make data read-only. Use the <apex:outputText> component instead of the <apex:inputField> component.
- Use JavaScript remoting. Unlike the <apex:actionFunction> component, JavaScript remoting doesn’t require an <apex: form> component. JavaScript remoting doesn’t reduce the overall view state of a page, but your page generally performs better without the need to transmit, serialize, and deserialize the view state. The tradeoffs are the loss of the reRender attribute and the necessity of additional JavaScript code to handle callbacks.

Comments
Post a Comment