Salesforce Visualforce Page View State

Have you ever encountered the “Maximum view state size limit” error on the Visualforce page that you developed even though you only capture very little information (e.g, like 3 input fields)?


Maximum view state size limit (135KB) exceeded. Actual view state size for this page was xxx.xxKB


The way that the view state works is that it is not only holding the value of the field that you capture on the page, but it also holds the value of any accessible objects/variables that you have declared in the controller/extension. For example, if you have an object list (e.g, List<Account>) and the list is holding a lot of records, you might encounter the view state size limit error even though you are not displaying result in the page.


Salesforce has a good explanation on Visualforce View State that gives you a good start if you are troubleshooting the issue. As a good developer, you should also follow the best practice guide to develop a performance optimized Visualforce page.