How to deal with the error: "Maximum View State size limit (135KB) exceeded" ?
Whenever I have worked on some Web Services requirement, I have generally come across this error message : "Maximum View State size limit (135KB) exceeded".
This time I encountered this known error when I was working on Account Online Passwords enhancement for February Release 2013.
So today I am taking time to jot down the way to minimize the probability of getting this error.
Few points about view state here:
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.
Salesforce allows Visualforce pages to have a maximum view state size of 135KB. The View State tab shows you which elements on your page are taking up that space. A smaller view state size generally means quicker load times.
To minimize your pages' view state, you can optimize your Apex controller code and remove any superfluous Visualforce components used.
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.
If your view state is affected by a large component tree, try reducing the number of components your page depends on.
Another important point here is the use of Transient keyword. The Transientvariable can not be saved, and shouldn't be transmitted as part of the view state for visual force page.
Point to be noted down is that:
Any apex component under
I could show you a scenario where how I reduced the View State size from around 136KB to around 85KB just by replacing with HTML tags
in conjuction with tag.
Initial piece of code:
Refined piece of code
Note: However, here we need to use CSS for formatting Table header values.
So we can see how significantly the view state size is reduced just by replacing one apex tag with HTML tag.