function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

How to reduce View State

I have a page where i am creating an interface to add attchments, urls and documents from salesforce.

When the Attachments are added I am getting a view state limit error. Can someone please suggest a solution.


I am getting the error message only when the file size exceeds a certain limit, I cannot make attachment transient as you can see I am using the attchment values to create a customer Attachment__c record. Can someone please tell me how can I make just the AttachmentBody Transient.




<apex:page standardController="Attachment" extensions="LandSlideFilePickerController" showHeader="false" sidebar="false">

<apex:pageBlock title="Select documents...">
<apex:form forceSSL="true">
<apex:pageMessages id="pm_PageMessages" />
<apex:pageBlockSection title="... from your computer" columns="1" >
<apex:outputpanel >
<strong>2. Click upload to attach your document. Attach multiple documents:</strong> repeat steps 1 and 2 to use multiple files.
(When the upload is complete, the file will appear in the "Documents to be faxed" list below.)<p />
<apex:inputFile value="{!Attachment.Body}" fileName="{!Attachment.Name}" fileSize="{!Attachment.BodyLength}" contentType="{!Attachment.ContentType}"/>
<apex:commandButton value="Upload" action="{!onUploadAttachment}" />




public with sharing class LandSlideFilePickerController {
public Id FolderId { public get; public set; }
public String SearchFilter { public get; public set; }
public String urlValue {public get; public set;}
public Boolean IsInternalUseOnly { public get; public set; }
public Id AttParentId{get;set;}
public Attachment a;

public LandSlideFilePickerController(ApexPages.StandardController controller) {
String pid = ApexPages.CurrentPage().getParameters().get('pid');
a = (Attachment) controller.getRecord();
a.ParentId = pid;
AttParentId = pid;


public void onUploadAttachment() {
Attachments__c ac = new Attachments__c();
ac.Name = a.Name;
ac.MIME_Type__c = a.ContentType;
ac.Sales_Resource__c = a.ParentId;
ac.Body_Length__c = String.valueOf(a.BodyLength);
ac.Value__c = URL.getSalesforceBaseUrl().toExternalForm() + '/servlet/servlet.FileDownload?file=' + a.Id;
database.insert (ac);


Have a look at this post

This will give enough information to solve the view stat problem