Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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()];
share|improve this question
    
Can you paste your update code. –  Sathya Feb 20 at 12:54
    
@Sathya I've just updated it. –  Hasan Khatib Feb 20 at 13:00
    
I have to declare a document variable as a transient...?? –  Sathya Feb 21 at 14:00
add comment

2 Answers

up vote 2 down vote accepted

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?

share|improve this answer
    
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" –  Hasan Khatib Feb 20 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 at 10:10
    
documents is a List<document> –  Hasan Khatib Feb 20 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 at 11:53
    
you are right MR :D, thx. –  Hasan Khatib Feb 20 at 12:19
add comment

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)
share|improve this answer
    
thank you, I was querying the body. –  Hasan Khatib Feb 20 at 12:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.