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
wongtwongt 

Maximum view state size limit (128K) exceeded. Actual viewstate size for this page was 142.438K

I'm trying to re-create the "Attach File" page using visualforce, but with big files, it is throwing the following error:

 

Maximum view state size limit (128K) exceeded. Actual viewstate size for this page was 142.438K

 

I've already been through the forums and the following post --

http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=10488#M10488

 

I tried commenting out lines to see if it would help, but the error doesn't go away.

 

 Here's the code --

 

 

public class OpportunityAttachFile {
public Opportunity oppty {get;set;}
public String fileName {get;set;}
public List<String> uploadedList {get;set;}
public Blob fileBody {get;set;}

public OpportunityAttachFile (ApexPages.StandardController controller) {
oppty = (Opportunity)controller.getRecord();
uploadedList = new List<String>();
}

public void attachFileAction() {
Attachment a = new Attachment();
a.ParentId = oppty.Id;
a.Name = fileName;
//NOTE: Here, I am commenting out segments of the code just to see if the error would go away, but it does not help.
//a.Body = fileBody;
//insert a;

//Clearing out the contents to avoid hitting viewstate limits
a = null;
}

public PageReference doneAction() {
return new PageReference('/' + oppty.Id);
}
}

 

 Help?
Best Answer chosen by Admin (Salesforce Developers) 
jwetzlerjwetzler

well yeah, because fileBody is the thing that is storing your file information, and that thing is getting stored in viewstate.

 

make fileBody transient, uncomment out your lines, and you should be fine.

All Answers

jwetzlerjwetzler

well yeah, because fileBody is the thing that is storing your file information, and that thing is getting stored in viewstate.

 

make fileBody transient, uncomment out your lines, and you should be fine.

This was selected as the best answer
Sree_NaniSree_Nani

Hi developers,

 

                         when I am using transient keyword with this code, I am  getting this type of error 

Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Body]: [Body]

 

can anyone tell me please

 

Thanks