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

Visualforce View State workaround


We use custom functionality that uses Apex Class to get a certain set of records and a custom visualforce page to display them.

It is used on several different record types on one object, but for two of those, there are too many results and we get the View State limit exceeded error. 

Is there a way to limit the amount of records it can display per page?
So there would be multiple pages if the amount exceeds the limit.

James LoghryJames Loghry
Time to go through your Visualforce with a fine tooth comb.  Make sure variables you don't need to post back and forth are marked as transient for one.  Also, if you're querying records, make sure to only bring back the fields (and records you need).  Can you use the standard set controller and pagination?  If so, that's also a good way to get around the view state limit.  If none of those work, you may also want to look into using RemoteActions and rolling your own client side pagination solution instead.
Hi Atheris,

Have you tried declaring the list with the records as transient ( This way it won't part of the view state and you will be able to display all the records. It will recreate with every refresh though... 

Hope this helps