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 varaibles 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.
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.
Now in the development mode enabled you would be getting an additional tab to view the View state.