What is View State in VisualForce page? I would like to know why we are using View state in VF page. Please help me .
In general HTTP is a stateless protocol. Therefore there is no native way to implement a "state" in HTTP.
In salesforce it can be necessary to be aware of a specific state. Such a state could be and is in the standard case the value of a property in your controller.
Let's imagine you implement a simple form in visual force:
The corresponding controller looks like this:
Salesforce will execute the page as follows (simplified):
Now the user is pressing the button "do"
There are many existing good and complete resources on what Visualforce view state is, how to use it, and how to manage it for good page performance.
I would suggest this intro page on the developer community site, which also has links for follow on reading for more detail.
The view state of a webpage is composed of all the data that's necessary to maintain the state of the controller during server requests (like sending or receiving date). So precisely view state -> implies the size of the page.
Whenever you use multiple forms in a VF page. Then typically the View state of the page exceeds its limit. The maximum limit should not exceed 135KB.
In order to reduce the view state, make use of the following:
A. "transient" keyword - to declare instance variables that can't be saved, and shouldn't be transmitted as part of the view state for a VF page.
for example :
B. Minimize the number of forms i.e
C. Refine your SOQL to retrieve only the data needed.
D. All public and private date members present in standard, custom and controller extensions are saved as a part of view state. so use transient variables which are not stored in state of page.
E. Instead of using