View state of the Visualforce Page comprises of the data which is required to recreate the page during server requests.
For Eg:- you have a form which on submit fires a error, Visualforce needs the variable to recreate the form on the UI. These variable sizes constitutes to the View State. Maximum view state holding capacity of Visualforce pages is 135Kb.
Best Practices to avoid View State: Now we know what is view state lets discuss about some good practices to avoid reaching the maximum limit of 135 Kb.
1) Avoid using multiple forms in the Visualforce Page.
2) Declare variables as Transient. Transient variables are not saved and therefore not transferred as a part of the view state.
3) Use Custom Settings to store read only Data. Custom settings are a part of Cache and does not constitute to the View State.
4) Refine your SOQL to fetch only the required data needed by the VF Page.
Enabling View State View state is an encrypted so native tool of browser won’t be able to show the view state. To enable View State, follow the steps below:
1. Go to setup –> Administration Setup –> Manage Users –> Users.
2. Select the user.
3. Click ‘Edit’ button.
4. Check the ‘Show View State in Development Mode’ checkbox.
5. Click ‘Save’ button.
Now in the development mode enabled you would be getting an additional tab to view the View state.