function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ssoftwaressoftware 

Error: Maximum view state size limit exceeded

Hi All,

 

I am getting the above error message for a visualforce page I developed. I minimized this issue by using the transient keyword in the controller code and by using readOnly="true" in the visualforce page.

 

However, my question is in case I get this error again, is there a way I can catch this error and display a more user friendly message?

 

For any DML operations in the controller code, I can catch the exceptions and use ApexPages.addMessages to display a user friendly message. However, where and how do I catch the view state error messages?

 

Thanks

Madhav

Best Answer chosen by Admin (Salesforce Developers) 
Cory CowgillCory Cowgill

As this is a System Error I don't think there is a nice way to catch this one. Its similar to when you have a Out Of Memory Error in Java, you can't catch it it crashes the application as it happens at the system level.

 

I can recommend that if you are hitting View State limits, one alternative is to use Javascript Remoting. If you use JavaScript Remoting your result sets are not subject to ViewState limits (you still have HeapSize limits though). The trade off is you have to use Javascript to manually manipulate the DOM, you won't be able to use the standard <apex:datatable> tags to display results, etc. 

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_js_remoting.htm

All Answers

Cory CowgillCory Cowgill

As this is a System Error I don't think there is a nice way to catch this one. Its similar to when you have a Out Of Memory Error in Java, you can't catch it it crashes the application as it happens at the system level.

 

I can recommend that if you are hitting View State limits, one alternative is to use Javascript Remoting. If you use JavaScript Remoting your result sets are not subject to ViewState limits (you still have HeapSize limits though). The trade off is you have to use Javascript to manually manipulate the DOM, you won't be able to use the standard <apex:datatable> tags to display results, etc. 

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_js_remoting.htm

This was selected as the best answer
ssoftwaressoftware

Hi Cory,

 

Thanks for your reply. I appreciate it. I will check out the javascript remoting option to see if it fits my requirements.

 

Thanks

Madhav