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
subaasubaa 

How to reduce View state size?

Hi,

 

I am getting the error, 'Maximum view state size limit (135KB) exceeded. Actual view state size for this page was 165.375KB' for one of the Visualforce page we used.

 

I could see some best practise to reduce this limit in Community. However, if anyone share me the way, you fixed this in your ORG would be more appreciated.

 

Thanks in advance.

 

Regards,

SuBaa

Best Answer chosen by Admin (Salesforce Developers) 
subaasubaa

Hi All,

 

Thanks for your comments. We couldn't control the size as we have four table in the same page and each table holds the record count of 500 plus. We provided the User, an option to change the page size dynamically according to the number of records in the table. We identified that the maximum view state error was occured when it was greater than or equal of 100. So we reduced the page size and tested. Now its not exceeding the max view state size value.

 

Using the transient keyword, we could manage the state size in very less proportion only.

 

Regards,

SuBaa

All Answers

Abhinav GuptaAbhinav Gupta

I hope you already tried stuff mentioned here 

 

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

 

http://wiki.developerforce.com/page/An_Introduction_to_Visualforce_View_State

 

Few quick ways that might help are 

  • Add transient keyword before variables, like lists used just for printing the tables.
  • Try recreating state, by querying again the database, storing in local lists, sets or maps will not work.
  • Declare some variable as static if possible, create static code block to recreate them in each request. 
  • Check your SOQL queries, if you are querying additional fields, never used or required on visualforce page. 

 

Hope this helps, best would be to share code so that we can suggest. Though i understand the code would be too big to fit in a forum question :)

Ankit AroraAnkit Arora

Blogged some more info here :

 

http://forceguru.blogspot.com/2010/11/best-practise-to-write-apex.html

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

kiranmutturukiranmutturu

if you tried above two posts patterns and still getting the prob then check your page components and confirm those are not dependent on <apex:form> tag.. then you can remove <apex:form> tag from then code and try 

subaasubaa

Hi All,

 

Thanks for your comments. We couldn't control the size as we have four table in the same page and each table holds the record count of 500 plus. We provided the User, an option to change the page size dynamically according to the number of records in the table. We identified that the maximum view state error was occured when it was greater than or equal of 100. So we reduced the page size and tested. Now its not exceeding the max view state size value.

 

Using the transient keyword, we could manage the state size in very less proportion only.

 

Regards,

SuBaa

This was selected as the best answer
Nadim DiazNadim Diaz
Try to use the tips mentioned here: http://cookingcode.wordpress.com/2014/06/09/salesforce-playing-with-the-view-state-how-can-i-reduce-it/  I hope you can solve the problem.