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
EIE50EIE50 

Urgent:: customize View State Error in Vf page

Hi,

 

I am standing at 30kb view state in the VF page and this will increase and go beyond 150kb. I know whats causing the issue or how to cut down on the issue. But right now what i am interested is, I need to know the size of the page in the controller and if the size is around 100kb, i would like to display a user friendly message saying that blah blah blah. Is this do-able? If so can any one please provide me the pointers or snippets. This fix is for time being and going forward we have plans to do the required which we are aware of to work around this issue.

 

thanks.

sfdcfoxsfdcfox

I'm not aware of a convenient way to determine this, although a close approximation might be to call JSON.serialize() on your entire class (so, JSON.serialize(this)) and see how big it is. True, it won't represent the actual size of your view state, but given what you can know, that's probably the best approximation I can come up with. There's no way that Apex Code can determine how big the view state is going to be directly; it knows only how big it will be relative to how much data it is storing for itself. You must keep in mind that "expresssions" take up additional storage page, and there is literally no way that Apex Code can read a page's expressions and know how much additional space is being used that way. I'm sure given some careful analysis, you could figure out some sort of algorithm given "if I have X data in my class, my page will be Y size, approximately."