I thought maybe I can do a work around of this issue "Maximum view state size limit (135KB) exceeded" by having the user insert all the document into salesforce first then select the documents that they want and then Ill do a merge and insert it into Document. but I am still getting the same error "Maximum view state size limit (135KB) exceeded. Actual view state size for this page was 1,112.297KB "

public with sharing class MultiDocController {

    Blob b;

public MultiDocController() {

         docNames = new List<SelectOption>();

         for (Document d :documents = [SELECT Id, Name , Body
                         from Document Where FolderId =: UserInfo.getUserId()  AND ContentType = 'application/pdf']){
            docNames.add(new SelectOption(d.Id,d.Name));

            String M =(String)JSON.deserializeStrict(responseBody,String.class);
            b = EncodingUtil.base64Decode(M);
            System.debug('Blob here' + b);

        Document record = new Document( FolderId = UserInfo.getUserId() ,AuthorId=UserInfo.getUserId(); Name='Tes'+'.pdf', Body = b ,ContentType='application/pdf;charset=UTF-8');
        System.debug('Record' + record);
        insert record;

I am using Component and I am not sure what else to share here. but I need to by pass that Error. and by the way samething happens if I do attachment record instead of Document record


<apex:component controller="MultiDocController" allowDML="true">
    <apex:attribute name="objId" type="String" description="The id of the object to manage attachments for" required="true" assignTo="{!sobjId}"/>
apex:form id="frm">

            <apex:commandButton action="{!save}" value="Click" reRender="frm"/>
        <!-- </apex:pageBlock> -->
  • 1
    Can you show us the Visualforce code? My guess is that you have a controller variable holding the input file, and you just need to clear it out before re-rendering the page. Dec 22, 2015 at 19:25
  • @JeremyNottingham Hi , thank you for the respond, Do you want the Controller code or Visual Force Component?
    – Metawaa
    Dec 22, 2015 at 19:28
  • @JeremyNottingham I just added
    – Metawaa
    Dec 22, 2015 at 19:30
  • Where is the variable b declared? Dec 22, 2015 at 19:42
  • 1
    this looks like a new problem - you should probably post the current code in a new question and @JeremyNottingham should post his solution as the answer that you should accept
    – cropredy
    Dec 22, 2015 at 20:32

1 Answer 1


Since you are storing the Blob value of the PDF in the class variable b, the entire Blob is considered part of the Visualforce view state, so the page can't be rendered.

One option is to only use the Blob with a local variable within the method where it is used. If it's not stored at the class level, it will not be retained in the view state.

The other option, which it sounds like you chose, was to make sure that b is set to null before re-rendering the Visualforce page. So the 1.1 MB PDF Blob is no longer stored within the controller class instance, and will not be counted against the view state.

  • Can I ask you another quick question?
    – Metawaa
    Dec 22, 2015 at 22:50

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