# Visualforce Attachment PDF Upload Maximum view state size limit (135KB) exceeded

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?

Class

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 MultiAttachmentController()
{
newAttachments=new List<Attachment>{new Attachment()};
getAttachments();
documents = [SELECT Id, Name , Body
from Document Where FolderId = '005G0000004gpv9']
}
{

{
}
}
public void save()
{

Test();
}

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

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

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


Component

<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: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:pageBlockSectionItem >
<apex:outputLabel value="Description"/>
<apex:inputText value="{!newAtt.Description}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:repeat>
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Done" action="{!done}"/>
</apex:pageBlock>
</apex:form>

• Try adding newAttachments.get(0).Body=NULL at end of the test() method – Vigneshwaran G Dec 21 '15 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 Dec 21 '15 at 17:40
• @VigneshwaranG I also do have blst.add(EncodingUtil.base64Encode(newAttachments.get(0).Body)); – Metawaa Dec 21 '15 at 17:43
• I would recommend you look into "transient" variables. – Sebastian Kessel Dec 21 '15 at 17:57
• @SebastianKessel I have also done that everywhere – Metawaa Dec 21 '15 at 17:58

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 Dec 21 '15 at 17:59