You need to sign in to do that
Don't have an account?
view state size exceeded - any suggestions?
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>
Hi,
View state size issue occurs when the variables declared as public are storing data greater than 135KB. So it is better to declare these variables as transient.
Transient Keyword: Use the transient keyword to declare instance variables that can't be saved, and shouldn't be transmitted as part of the view state for a Visualforce page.
For more detail follow the below link :
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_keywords_transient.htm
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
All Answers
Hi,
View state size issue occurs when the variables declared as public are storing data greater than 135KB. So it is better to declare these variables as transient.
Transient Keyword: Use the transient keyword to declare instance variables that can't be saved, and shouldn't be transmitted as part of the view state for a Visualforce page.
For more detail follow the below link :
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_keywords_transient.htm
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
tried this earlier. Declared a transient instance variable, instantiated it in the controller constructor and then when trying to access it within an append method, got a null pointer exception. If i remove the transient keyword, then the null pointer error went away - that is, it was able to find the variable as initiliased in the constructor.
while the transient variable isn't useful for my purposes, it did seem to clarify how state is maintained and strongly suggests that what I had hoped to implement may not be possible. The currently suggested workaround is to store the blobs to the DB and simply keep a record of where to retrieve the values from. It seems an imperfect solution but may serve my purposes.
Anyhow, thank you for the help.
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.