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
stcforcestcforce 

view state size exceeded - any ideas?

i'm trying to upload some files and store these on the controller and eventually send these. The error i get back is "Maximum view state size limit (135KB) exceeded. Actual view state size for this page was 772.562KB". I need to be able to be able to store some blobs (upto 5mb of files extracted from attachments, files on c: and documents) on the controller, but the view state size seems to preclude this. The following is the simplest possible code to illustrate the problem at hand (a file is select, the savex operation causes bound variables to load, the page refreshes and exceeds limits) and a solution to this would enable me to address my actual code (too long to post). I would appreciate any help that could be given. 

thank you.

 

 

 

public withsharingclass docController {

   

public document document {get; set;}

 

public docController() {

        document =new document();

    } 

   

publicvoid savex()    {    }

}

 

<apex:page controller="docController">     <apex:messages />    

<apex:form id="theForm">       <apex:pageBlock >          

 <apex:pageBlockSection >             <apex:inputFile value="{!document.body}" filename="{!document.name}"/>                         <apex:commandButton value="Save" action="{!savex}"/>          

 </apex:pageBlockSection>        </apex:pageBlock>    

 </apex:form>

</apex:page>



Best Answer chosen by Admin (Salesforce Developers) 
Chamil MadusankaChamil Madusanka

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

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

All Answers

Navatar_DbSupNavatar_DbSup

Hi,

 

This is a duplicate post please make sure that you do not post any duplication questions on discussion board. So I request you to please remove it. For information regarding this post you can go to the following link:

 

http://boards.developerforce.com/t5/General-Development/view-state-size-exceeded-any-suggestions/m-p/424289/highlight/false#M68882

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

Chamil MadusankaChamil Madusanka

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

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

This was selected as the best answer
stcforcestcforce

tried using transient earlier. The code had been working for small attachments, but adding the transient keyword to the instance variable (list storing the attachments) caused a null pointer exception. It seemed to lsot it's value between the controller constructor and the subsequent methods - but only when declared using transient.

stcforcestcforce

a closer look at transient methods offered some insight into the nature of the problem (how state is stored). It seems likely what i had hoped to achieve is impossible. Thanx Chamil and Ankit for the assistance.

sapthagiri_186sapthagiri_186

Hello all,

 

I am trying to use transient for attachment, but when I am saving it, it is showing me "Null" in Attachment Name and Attachment Body. If I am not using transient, I can store the attachment only upto a size of 135Kb. But we can actually store upto 5MB in developer edition.

 

And is there is way to catch the "Maximum view state size limit (135KB) exceeded." exception. 

 

Best Regards

GoForceGoGoForceGo

You need to set attachment.Body = null after you save it to the database. If you don't, it is part of view state size.