4

I have implemented custom search and displaying 10000 records on page using pagination. Pagination is done by using StandardSetController only. I also have implemented sorting of data. Can anybody suggest any solution to reduce view state?

ca_peterson
  • 22,983
  • 7
  • 69
  • 123
user3761
  • 189
  • 2
  • 9
  • 2
    http://salesforce.stackexchange.com/questions/4537/how-to-reduce-a-large-internal-view-state-what-is-in-the-internal-view-state Have a look at the link mentioned .Please post your code too to see if we can make some variables transient (variables not necessary to maintain states).Alternatively since now server side view state can be tried after winter 14 you can explore that.Or even if you can afford redesign Javascript remoting can be handy. – Mohith Shrivastava Nov 03 '13 at 12:36
  • 1
    Also 10000 is too much data on a single page .I believe you can reduce this number to stop hitting view state . – Mohith Shrivastava Nov 03 '13 at 12:37
  • Yes the answer referenced by @MohithKumar gives some good insight on what might be causing this. If your page is complex with lots of VF components, it could well be something called 'internal viewstate'. – Andrew Fawcett Nov 03 '13 at 13:13
  • 2
    Just wanted to clarify that using server side view state doesn't change the amount of data which can be stored. Rather it changes where the data is stored. http://salesforce.stackexchange.com/a/17966/660 – Mark Pond Nov 03 '13 at 17:54

2 Answers2

3

There are two primary components of the view states, (1) is the data required to store the state of your controller, and (2) additional "housekeeping" info to store the DOM tree and lots of other stuff that gets rolled up into the mysterious and undocumented internal view state (see this question fore more discussion).

Controller Data - Use transient

To reduce the amount of data needed to store the state of your controller you can make liberal use of the transient keyword so that only data that is truly needed to maintain state is sent over to the client. Anything you can re-query, or otherwise re-create, can be ditched.

Internal View State - Avoid apex components

If you're running into internal view state issues (this typically only happens with pages with large collections), the best way to reduce it is to switch to using standard HTML components instead of apex components. Each apex component adds a certain amount of "weight" to the page (and some much more than others, i.e. lookup fields), so switching to non-apex components can help reduce the drag.

For example, replace

<apex:outputField value="{!Case.AccountId}"/>

With it's stripped equivalent (kind of)

<a href="{!URLFOR($Action.Account.View,Case.AccountId)}">{!Case.Account.Name}</a>

Ralph Callaway
  • 24,529
  • 17
  • 112
  • 190
  • Can you please make me understand how to make liberal use of transient keyword ? If I use this keyword liberally I get nullpointerexceptions – Jarvis May 04 '17 at 16:52
1

If you are using the StandardSetController for pagination, your viewstate shouldn't really be blowing up since you shouldn't need all 10,000 records showing on the screen at the same time.

From your question it sounds like you are querying out 10,000 records based on some custom search filter and sorting them in apex. If you really need this, consider using a RemoteAction function to retrieve the records required and then sort the data in javascript.

Not knowing what you are trying to achieve makes answering the question difficult, but you could also consider using reports and list views instead

user2610036
  • 1,039
  • 1
  • 8
  • 21