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
IatrjcIatrjc 

Maximum view state size limit (135KB) exceeded.

Hi all,

 

I am receiving the following error when trying to load a rather complex Visualforce page: 

"Maximum view state size limit (135KB) exceeded."

 

I've done some research on the various causes that can be behind this issue and verily, my page is guilty of most of them, however what's throwing me for a loop is this - I only exceed my view state size on my full sandbox. For the exact same page (both Visualforce page and it's respective Controller), and the exact same inputs, my view state on Sandbox is roughly 2.5x as large. On Production, I'll average a view state of 50kb - 60kb, while on sandbox with all but the most trivial of inputs I'll be anywhere from 130kb - 190kb. This is a huge impediment for 2 reasons:

 

1) It's really hard to develop on my sandbox when I can't view the outputs

 

2) This is a mission critical vf page. If this issue starts appearing on prod it's going to be bad news bears

 

So, my question is, what can influence the size of View State beyond the vf page and controller (which in my case are identical in both environments)? 

 

Cheers,

Kevin

 

Maros SitkoMaros Sitko
here is good article http://wiki.developerforce.com/page/An_Introduction_to_Visualforce_View_State

you should try use less apex tags and more html tags, decrease number of input fields and use transient keyword for variable, which you do not need store for vf (http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_keywords_transient.htm )
IatrjcIatrjc

Hi Maros,

 

Thank you for your suggestions. I have already incorporated all of those techniques into the page. 

 

However, my question still stands - Why are my view state sizes so drastically different from Production to Sandbox?

tggagnetggagne

You've already covered the transient issue.  The  best solution I've found is to avoid it altogether by using Javascript Remoting.

 

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

 

With remoting you can't store "state" on the browser, but not all pages need state.  And sometimes the only state that's needed fits comfortably inside javascript variables.  Our experience is the pages also tend to demonstrate crisper response to users.

JK84JK84

Hi,

 

The answer for "Why the viewstate is higher in Sandbox than production" can be found by enabling the development mode and observing the view state (Check the "Show the view state in Development mode" in your user settings).

 

The view state tab, shows a break down of the size taken by each component in your code.

 

Hopefully it should point you towards the components that have a different view state in the sandbox and production.

 

Thanks

JK

 

Maros SitkoMaros Sitko
codes are the same? Do you show input fields for existing records? that means that in production you have for example 10 records and in sandbox 1000 records, and you are shown all records on VF page in editable mode (so all fields are input element on VF page)
JK84JK84

Hi,

 

If there are huge number of records, you will have to implement pagination to avoid view state error and when you execute the VF page with development mode on, it does show the viewstate taking into account the number of records being queried. Could be 1000 in Sandbox or 10 in production.

 

 

Thanks

JK

 

IatrjcIatrjc

Hi JK84, 

 

An excellent suggestion. I did some investigation. There are slight difference amongst the size of child objects used in the page. However, the vast majority of the disparity is in 'Internal State', which I can't drill down on. Please view the image here. Any suggestions how I can reduce this?

 

Cheers,

Kevin

 

 

JK84JK84

Hi Kevin,

 

We've solved one part of the puzzle ..to find which part of the page is causing the issue. Now, on the important part... "Internal" viewstate is something difficult to crack, but following are some links which had a mention of similar kind of issue and were resolved.

 

Could you check if yours falls into anyone of these categories :

 

http://boards.developerforce.com/t5/Visualforce-Development/Reducing-the-size-of-the-Internal-node-of-the-View-State/td-p/294687

http://salesforce.stackexchange.com/questions/4537/how-to-reduce-a-large-internal-view-state-what-is-in-the-internal-view-state

 

And finally, as per the below url, "Internal" viewstate is not in the control of developers, so if none of the solutions in above URL's work, then you might have to raise a ticket with salesforce support team to know the exact cause.

 

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

 

Let me know if its resolved, would be eager to know ....some new points to learn .......

 

Thanks

JK