What is View State in Salesforce

View State in Salesforce
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 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.

Enabling View State View state is encrypted so native tools of browser wont 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.

view state
5. Click ‘Save’ button.

Now in the development mode enabled you would be getting an additional tab to view the View state.

Viewer
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s