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
Kim D.ax1409Kim D.ax1409 

Max view state size limit error

We created a class to pull all comments (custom object) related to a record (ie, account, case, opportunity, etc) and displays the comments.  We finally ran into this max view limit error and I'm not sure what I can do to get around this.  We don't delete comments so these will continue to increase, especially with high-profile accounts.

Our original SF developer is no longer here and would really appreciate getting some help on this issue.  I can send you the Apex script we have.  We thought about limiting the number of records we get back, but then our users wouldn't be able to see older comments.  We also considered creating another account record to hold older comments, but that's not ideal and besides, I wouldn't know how to do that.



 
Roy LuoRoy Luo
If you only need to view (no edit/update) the comments, don't use out of box apex controlls, use html equivalents and that will save you the trouble of view state size limit.

For example:

BAD: <Apex:outputText value="{!yourValue}" />
GOOD: {!yourValue}

The view state size limit is 135K and without paging the Apex controls will eat up 135K easily.
Ravi Dutt SharmaRavi Dutt Sharma
Can you please provide the code. I had the same issue working with Attachments and the fix was pretty simple
Kim D.ax1409Kim D.ax1409
@Roy, we do have to give users the ability to edit existing comments so that wouldn't work.  Thanks for the suggestion.

@Ravi, how do I send you the code?  I don't see a way to attach it here.  Thanks in advance!
Roy LuoRoy Luo
If you need ingrid editing, then paging is the only way. The other alternative would be a readonly grid (table) with an Edit button to popup an editor for Comments on that row.
Kim D.ax1409Kim D.ax1409
@Roy: we are currently doing that too, Edit button opens a popup. 
Roy LuoRoy Luo
Then using html controls will definitely work, without view state size limit issue.