I have done some research and most of the solutions is not working for me. I am trying to upload multiple pdf files, and I right now it doesnt even let me upload a single file due to the Maximum view State. Is there a way of bypassing the stats view and make the size more than 135kb?


public with sharing class MultiAttachmentController {
 public Id sobjId {get; set;}
    public String pdfBody{get;set;}
    public List<Document> documents {get;set;}
    public List<Attachment> attachments; 
    public List<Attachment> newAttachments {get; set;}
    public static final Integer NUM_ATTACHMENTS_TO_ADD=5;
 public MultiAttachmentController()
        newAttachments=new List<Attachment>{new Attachment()};
         documents = [SELECT Id, Name , Body
                         from Document Where FolderId = '005G0000004gpv9']       
 public void addMore()

        for (Integer idx=0; idx<NUM_ATTACHMENTS_TO_ADD; idx++)
            newAttachments.add(new Attachment());
 public void save()


    public void Test(){
List<String> blst = new List<String>();
//attach file from page

String bodyStr = '["'; 
Integer i = 0;
for(String newSt: blst){
     bodyStr += newSt + '"';
     if(i < blst.size())
        bodyStr += ',"';
  bodyStr += ']';

System.debug('bodtest:    ' + bodyStr);


<apex:attribute name="objId" type="String" description="The id of the object to manage attachments for" required="true" assignTo="{!sobjId}"/>
    <apex:form id="attForm">
        <apex:pageBlock title="Upload Attachments">
            <apex:repeat value="{!newAttachments}" var="newAtt">
                <apex:pageBlockSection columns="3">
                   <apex:pageBlockSectionItem >
                        <apex:outputLabel value="File"/>                         
                        <apex:inputFile value="{!newAtt.body}" filename="{!newAtt.name}"/>
                    <apex:pageBlockSectionItem >
                        <apex:outputLabel value="Description"/>                      
                        <apex:inputText value="{!newAtt.Description}"/>
            <apex:commandButton value="Add More" action="{!addMore}"/>
            <apex:commandButton value="Save" action="{!save}"/>
            <apex:commandButton value="Done" action="{!done}"/>
  • Try adding newAttachments.get(0).Body=NULL at end of the test() method Commented Dec 21, 2015 at 17:35
  • @VigneshwaranG thanks for the reply, I did this public void Test(){ newAttachments.get(0).Body = NULL; List<String> blst = new List<String>(); and now System.NullPointerException: Argument cannot be null.
    – Metawaa
    Commented Dec 21, 2015 at 17:40
  • @VigneshwaranG I also do have blst.add(EncodingUtil.base64Encode(newAttachments.get(0).Body));
    – Metawaa
    Commented Dec 21, 2015 at 17:43
  • I would recommend you look into "transient" variables. Commented Dec 21, 2015 at 17:57
  • @SebastianKessel I have also done that everywhere
    – Metawaa
    Commented Dec 21, 2015 at 17:58

1 Answer 1


The only way to reduce view size of the Visual force to monitor view size of the page and checking which areas have view size is exceeding.

You can monitor view state performance through the View State tab in the development mode footer and take the following actions:

Use the transient keyword in your Apex controllers for variables that aren’t essential for maintaining state and aren’t necessary during page refreshes.

If you notice that a large percentage of your view state comes from objects used in controllers or controller extensions, consider refining your SOQL calls to return only data that's relevant to the Visualforce page.

If your view state is affected by a large component tree, try reducing the number of components your page depends on.

This may help you to reduce the view size of the page.

  • Hi, thank you for reply, I have used transient on every variables that I have before and still samething. Let me do the view state tab
    – Metawaa
    Commented Dec 21, 2015 at 17:59

You must log in to answer this question.

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