+ Start a Discussion
Pavan kumar 546Pavan kumar 546 

what is view state and need a steps how can we reduce view state without help of transient

 view state and need a steps how can we reduce view state without help of transient
SRKSRK
View state is a state of you VF page, which help salesforce to regenerate VF page when it come back from server

For exmaple, when you create a VF page having a some input fields, no consider that you load this page with some value and there are some required field on this page and when you click on a button this page will get submited to server then when server replay back your page should be loaded in same state as it was before submit button click, to mantain this salesforce exchange data between VF and saevers and this information which salesforce mantian is know as View state,

In simple words , it is a state ot view which you are view and salesforce use it to regenerate your page, when ever there reply come back from server

other then transient, you can user VF remoting and @ remote action, as it wont transfer View state

Also you can user mode=readonly, it a property of <page> tag
Himanshu ParasharHimanshu Parashar
 As its name suggests, it holds the state of the page - state that includes the components, field values and controller state.


The data in the view state should be sufficient to recreate the state of the page when the postback is received. To do this, it stores the following data:
  1. All non-transient data members in the associated controller (either standard or custom) and the controller extensions.
  2. Objects that are reachable from a non-transient data member in a controller or controller extension.
  3. The component tree for that page, which represents the page's component structure and the associated state, which are the values applied to those components.
  4. A small amount of data for Visualforce to do housekeeping.


Developer environments have a view state inspector, which lets you view the contents of the view state. This information can help you in optimizing the view state size. Once enabled, it shows up as a tab in Development Mode, as follows. you can enable that from 

Edit User-> Select view state checkbox after development mode checkbox.

User-added image


Check your view state as shown above

Here are some quick tips which will help you to reduce view state size without using transient keyword

 
  1. If your view state is affected by a large component tree, try reducing the number of components your page depends on.
  2. Avoid SOQL queries in your Apex controller getter methods.
  3. use private setter for elements where you are not updating value from visualforce page.
  4. Decrease collection items if they are not going to be used in page.
  5. define private if they are not used on visualforce page.
  6. If you notice that a large percentage of your view state comes from objects used in controllers or controller extensions, consider refining your SOQL calls to return only data that's relevant to the Visualforce page.



Thanks,
Himanshu
jyothsna reddy 5jyothsna reddy 5
Hi Pavan Kumar,   

View state holds the state of Visual force page.
 The view state of a web page is composed of all the data that's necessary to maintain the state of the controller during server requests (like sending or receiving data). Since the view state contributes to the overall size of your page, performance of a page can depend on efficiently managing the view state. The View State tab in the development mode footer provides information about the view state of your Visualforce page as it interacts with Salesforce.
 
If your not using input tags in visual force page form is not required.Without form Viewstate is not created.

How to reduce View state:

Minimize number of form on a page.  Use apex:actionRegion instead of using 2 or more forms.
Refine your SOQL to only retrieve the data needed by the page.
All public and private data members present in Standard, Custom and Controller extensions are saved.
The transient variables are not passed to view state and therefore not stored in View State.

Please check below link for more information.I hope that it will help you.







jyothsna reddy 5jyothsna reddy 5

Please check below link for more information.I hope that it will help you.


https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_best_practices_performance.htm
Arjun Soni 16Arjun Soni 16
Hello Paven,

i think this may be help you to understand view state in simple words.

here in visual force pages view is coming from UI where it says how it should look and state says this is the way it should looklike.
So the view state is nothing but a state of visualforce page or we can say copy of page that contain only those page members which are usfull to generate same page which we have sent out in our request(by clicking on submit or some other button) to server and moreover view state is nothing but a variable in vf's which hold all the component of view state and and salesforce servers only can undestand it and post back the same page with result as it was before clicking on the submit button.

If u find it best to suite for your better understanding please make it a best answer.

Regards
Arjun
 
Arjun Soni 16Arjun Soni 16
i think this may be help you to understand view state in simple words.

here in visual force pages view is coming from UI where it says how it should look and state says this is the way it should looklike.
So the view state is nothing but a state of visualforce page or we can say copy of page that contain only those page members which are usfull to generate same page which we have sent out in our request(by clicking on submit or some other button) to server and moreover view state is nothing but a encrypted form field in vf's which hold all the component of view state in encapsulated form and salesforce servers only can undestand it and post back the same page with result as it was before clicking on the submit button.

there is a data type called transient but instead of that there are some other options we have to reduce the view state in vf pages

1. Minimize number of form on a page.  Use apex:actionRegion instead of using 2 or more forms.
2. All public and private data members present in Standard, Custom and Controller extensions are saved.
3. The transient variables are not passed to view state and therefore not stored in View State.
4. Refine your SOQL to only retrieve the data needed by the page.
5. don't use pagemessage attribute in vf pages.

If u find it best to suite for your better understanding please make it a best answer.

Regards
Arjun