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
InsightTeamInsightTeam 

Max View State Size Limit Error

We have a class that grabs specific attachments and sends them out along with a proposal as an email.  This has worked fine for the last 8 months since the code was written.  I know salesforce did an update over the weekend and since then we are getting the following error everytime we try to click the custom button in Opportunities to send out the proposal:

 

Maximum view state size limit (135KB) exceeded. Actual view state size for this page was 139.656KB 

 

I do have some programming experience - just not in Apex so this might be something I can handle with the right direction.  Basically to sum it up, the code grabs specific attachments, an intro letter and some details from the opportunity and sends an email.  This has been resolved by adding:

 

transient Blob fileBody;

 

bvramkumarbvramkumar

I usually follow the below to solve the Viewstate error:

 

1. Remove  unnecessary data members from the controller class and try to suffice them by using local variables. Consider using transient variables etc. In your code I see fileBody as a Blob variable as a data member but only used in one function. Cant this made a local variable? 

 

2. If you are using collection variables such as Lists, sets and Maps as data members. Let these type of variables be loaded with data required at that point of time in page's execution. Clear/nullify these collection variables when they can be.

 

3. Try not to use too many pageBlocks. Try loading the components of the Page dynamically rather than loading all of them at once. etc.

 

4. Basically you need to optimize your Logic so that the data transfered between postbacks is only as much as required.

 

These points have helped me several times to resolve the error... Hope this helps...