8

I am trying to implement a page that I will upload files through it, but I keep having this error

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

Here is my visualforce form

<apex:pageBlockSection columns="3">
    <apex:pageBlockSection >
      <apex:pageBlockSectionItem >
         <apex:inputFile value="{!document.body}" filename="{!document.name}" id="file"/> 
     </apex:pageBlockSectionItem>  
     <apex:pageBlockSectionItem >
        <apex:outputLabel value="Description" for="description"/>
        <apex:inputTextarea value="{!document.description}" id="description"/>
     </apex:pageBlockSectionItem>
 </apex:pageBlockSection>
 </apex:pageBlockSection>
 <apex:pageBlockButtons >
    <apex:commandButton action="{!upload}" value="Upload"/>
 </apex:pageBlockButtons>

and here is my APEX code

public List<Document> documents{set;get;}
public Document document 
{
  get 
  {
    if (document == null)
      document = new Document();
      return document;
  }
  set;
}
document.AuthorId = UserInfo.getUserId();
    document.FolderId = account.ID;
    try {
       insert document;
    } catch (DMLException e) {
       ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error'));
    } finally {
       document.body = null;
       document = new Document();
       documents = [SELECT Query];
    }

What is the problem here ?


Update: The query was like this

documents = [SELECT Description, body, Id, Name, Url FROM Document WHERE
AuthorId =:UserInfo.getUserId()];

but it works after I removed body

documents = [SELECT Description, Id, Name, Url FROM Document WHERE
AuthorId =:UserInfo.getUserId()];
3
  • Can you paste your update code.
    – Sathya
    Feb 20, 2014 at 12:54
  • @Sathya I've just updated it. Feb 20, 2014 at 13:00
  • I have to declare a document variable as a transient...??
    – Sathya
    Feb 21, 2014 at 14:00

2 Answers 2

4

Try making your Document object transient. Its not evident from your code. And what is that 'documents' in the end, where you try to query something?

6
  • Yes actually, but the error has changed to this "Maximum view state size limit (135KB) exceeded. Actual view state size for this page was 158.328KB" Feb 20, 2014 at 10:02
  • 1
    Dont change the question after someone answers. That makes the answer completely out of context. Open a new question if required, after closing the previous one. Anyway, I have updated my answer.
    – AslamK
    Feb 20, 2014 at 10:10
  • documents is a List<document> Feb 20, 2014 at 11:10
  • I think that might be the problem. Dont query the document body in that query (the query in the question is not complete).
    – AslamK
    Feb 20, 2014 at 11:53
  • you are right MR :D, thx. Feb 20, 2014 at 12:19
2

Following information can be provided according to the question:-

  • Make document variable transient and also make document = null;
  • Also do not query body field in SOQL if you are querying that. e.eg; [SELECT id, body FROM Document]. This may hit controller heap size and page viewstate (if referenced on Visualforce page)
3

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .