Apex

What is View State in Salesforce

What is View State in Salesforce

What is 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.

What is View State in Salesforce

5. Click 'Save' button.

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

What is View State in Salesforce

About Saurabh Dua

3 comments:

  1. Thank you for sharing a post articles that are beneficial to the reader. I really enjoyed reading your blog, by reading blog made me become very inspired and gain knowledge
    ------------------------------------------------------------
    noi that o to | do choi o to | do choi xe hoi

    ReplyDelete
  2. i was searched many web sites for better definition to the view state.

    Finally i am happy with this blog .

    Thanks sir...

    ReplyDelete

Powered by Blogger.