Sign up ×
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="{!}" id="file"/> 
     <apex:pageBlockSectionItem >
        <apex:outputLabel value="Description" for="description"/>
        <apex:inputTextarea value="{!document.description}" id="description"/>
 <apex:pageBlockButtons >
    <apex:commandButton action="{!upload}" value="Upload"/>

and here is my APEX code

public List<Document> documents{set;get;}
public Document document 
    if (document == null)
      document = new Document();
      return document;
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 '14 at 12:54
@Sathya I've just updated it. – Hasan Khatib Feb 20 '14 at 13:00
I have to declare a document variable as a transient...?? – Sathya Feb 21 '14 at 14:00

2 Answers 2

up vote 3 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 '14 at 10:02
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 '14 at 10:10
documents is a List<document> – Hasan Khatib Feb 20 '14 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 '14 at 11:53
you are right MR :D, thx. – Hasan Khatib Feb 20 '14 at 12:19

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.; [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 '14 at 12:19
@Ashwani : Have look into this problem plz -… – Nilesh Mendhe Mar 30 at 7:59
@Nilesh you CSN use tansient keyword to prevent viewstate. – Ashwani Mar 30 at 12:49
@Ashwani : CSN ? And Its giving me some sort of error msg when I declare variable as Transient. It works with some variable but still go for Viewstate error. – Nilesh Mendhe Mar 31 at 6:05

Your Answer


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.