You need to sign in to do that
Don't have an account?
TehNrd
Error: Maximum view state size limit (128K) exceeded.....uh oh
So I never thought I would be hitting this limit but here I am. I did a search on this and nothing came up so it looks like I'm one of the few to hit this limit.
Maximum view state size limit (128K) exceeded. Actual viewstate size for this page was 174.281K.
Hmm. So what can I do to measure this and control it. Is there any field I can output to monitor what my viewstate while developing?
Thanks,
Jason
Message Edited by TehNrd on 08-26-2008 03:03 PM
Maximum view state size limit (128K) exceeded. Actual viewstate size for this page was 174.281K.
Hmm. So what can I do to measure this and control it. Is there any field I can output to monitor what my viewstate while developing?
Thanks,
Jason
Message Edited by TehNrd on 08-26-2008 03:03 PM
All Answers
I've been doing some more testing and it looks like I was just passing too much data back from the controller to the page. I had two List of opportunities with a size of 1000. Only one of these was being used on the page. There was also another list of a custom class/object that displayed all of the Accounts that were returned. Both of theses Lists were used in a dataTable.
What I have end up doing is running a query on opps that meet the criteria entered and then create a consolidated list of the Accounts that were returned. Then a user can click on one of the accounts and this will render a new panel that shows the opps for the account selected.
I have noticed that I can only create two Lists of Opportunities before it errors out but with my custom object/class I can create at least 4, maybe more.
-Jason
The strange thing about this whole thing is that, although we get the error (which seems to happen in IE 6 more so than FF 3), the file uploads just fine and is associated with the appropriate custom object record.
Has the internal development tool you (Doug) mentioned been released since you originally posted this a few months back?
I am also facing the same issue. We are using a small pop-up window and display Visualforce page in it. It contains only one <apex:inputFile> control and 1 textboxes. But, when i try to upload images of size greater than 100KB it gives the following error:-
"Maximum view state size limit (128K) exceeded. Actual viewstate size for this page was 169.812K"
Please provide some pointers on the same.
Regards,
Anshul Verma
Hi Doug,
I am also seeing this problem "Maximum view state size limit (128K) exceeded. Actual viewstate size for this page was 140.797K". I'm using "inputFile" to upload a document, but instead I save it as an attachment against an account record. Below is the code of my visualforce page and controller extension. FYI - I'm trying to upload the apex language reference pdf as a test (4.233 mb - http://www.salesforce.com/us/developer/docs/apexcode/salesforce_apex_language_reference.pdf).
Visualforce page:
<apex:page standardController="Document" extensions="TestFileUploadPageControllerExtension"> <apex:form > <apex:pageBlock title="Attach file" mode="edit"> <apex:pageBlockSection columns="1" > <apex:pageBlockSectionItem > <apex:outputLabel value="Select a file" for="inputFile"/> <apex:inputFile id="inputFile" value="{!document.Body}" filename="{!document.Name}"/> </apex:pageBlockSectionItem> </apex:pageBlockSection> <apex:pageBlockButtons location="top"> <apex:commandButton action="{!doAttach}" value="Attach" id="attachButton"/> <apex:commandButton action="{!done}" value="Done" id="doneButton"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>
Controller extension:
public class TestFileUploadPageControllerExtension { //reference to standard controller private ApexPages.StandardController controller; public TestFileUploadPageControllerExtension(ApexPages.StandardController controller) { this.controller = controller; } public void doAttach() { System.Debug('##################################'); //get uploaded document Document doc = (Document)this.controller.getRecord(); System.Debug('doc: '+doc); //create attachment from document Attachment a = new Attachment(); a.Body = doc.Body; a.ContentType = doc.ContentType; a.Name = doc.Name; a.ParentId = '0018000000OtgFl'; //hard coded account id Database.SaveResult sr = Database.Insert(a); System.Debug('Attachment SaveResult: '+sr); } public PageReference done() { PageReference pageRef = new PageReference('/0018000000OtgFl'); //hard coded account id return pageRef; } }
Your help is appreciated.
I've been getting the same error. I'd really appreciate it if someone could shed some light on the issue.
The app I'm developing allows users to upload images into the user's Documents tab, grabs the URL and creates a record of a custom object I've named Gallery which displays the image in a formula field IMAGE() function. When a user uploads an image about 105 Kb or larger in size, they get the error. However, the image is still successfully stored into the Documents tab and the Gallery record successfully grabs the URL and displays the stored image. It works, sure, but I don't want users to keep seeing this error.
The controller class creates a Document variable that is further stored into Documents using insert.
Is this to be expected when applying image uploading from a Visualforce page to user functionality? Or is there perhaps something I'm doing wrong?
public class UploadController
{
ApexPages.StandardController controller;
public UploadController(ApexPages.StandardController c){
System.debug('@@@@@@@@ UploadController');
this.controller = c;
}
public PageReference docSave()
{
System.debug('@@@@@@@@ docSave');
String origURL = System.currentPageReference().getUrl();
PageReference success = new PageReference('/apex/UploadSuccess');
PageReference failure = new PageReference(origURL);
if(someCondition)
{
Document d = (Document) controller.getRecord();
String urlPrefix = '/servlet/servlet.FileDownload?file=';
System.debug('@@@@@@@@ document name: '+d.name);
d.folderid = UserInfo.getUserId();
System.debug('@@@@@@@@ document folder id: '+d.folderid);
d.IsPublic = true;
insert d;
d.Url = urlPrefix + d.Id;
Gallery__c g = new Gallery__c();
g.Image__c = d.Url;
insert g;
System.debug('@@@@@@@@ document object id: '+d.id);
System.debug('######## document content type: '+d.type);
System.debug('@@@@@@@@ redirect');
return success;
}
else
{
ApexPages.addMessage(new ApexPages.message(
ApexPages.severity.WARNING,'The upload failed. Please retry or contact an administrator.'));
return failure;
}
}
}
Nope, that didn't do the trick. =(
I also tried transient on the Document instantiation, but that doesn't change anything.
Does anyone know if there is a way to reduce the image size of a document and/or check for the size of a document? I think I'll have to limit the user's upload somehow and display a warning message if the attempted upload is too big.
OK, so I just got it to work because I reevaluated my code:
public class UploadController
{
ApexPages.StandardController controller;
public UploadController(ApexPages.StandardController c){
System.debug('@@@@@@@@ UploadController');
this.controller = c;
}
public PageReference docSave()
{
System.debug('@@@@@@@@ docSave');
String origURL = System.currentPageReference().getUrl();
PageReference success = new PageReference('/apex/UploadSuccess');
PageReference failure = new PageReference(origURL);
if(someCondition)
{
transient Document d = (Document) controller.getRecord();
String urlPrefix = '/servlet/servlet.FileDownload?file=';
System.debug('@@@@@@@@ document name: '+d.name);
d.folderid = UserInfo.getUserId();
System.debug('@@@@@@@@ document folder id: '+d.folderid);
d.IsPublic = true;
Database.SaveResult sr = Database.Insert(d);
Gallery__c g = new Gallery__c();
g.Image__c = urlPrefix + sr.getId();
insert g;
System.debug('@@@@@@@@ document object id: '+d.id);
System.debug('######## document content type: '+d.type);
d.Body = null;
d = null;
System.debug('@@@@@@@@ redirect');
return success;
}
else
{
ApexPages.addMessage(new ApexPages.message(
ApexPages.severity.WARNING,'The upload failed. Please retry or contact an administrator.'));
return failure;
}
}
}
Before when I was setting d.Body = null, it would not display the error but as a result, the document and image display would not properly function.
With SaveResult, I'm still able to refer to the value of the stored Document's Id. Storing the value into d.Url was a stupid mistake. I should have stored into Image__c from the beginning.
Thanks a bunch guys!
Hi all,
I'm also running into the viewstate limit, but in my case I'm not doing any file uploads. The code is fairly complex and I'd like to be able to pin point the cause but without the debug tools it's pretty difficult. It'd be great if the view state debug tools could be released to the public.
Thanks!
Scott
Agreed.
Based on my completely unscientific testing, collections of sObjects seems to be the biggest culprit when adding size to viewstate. Other than this it is hard to tell what is going on with the view state.
Hi all,
After playing around with it some more, it appears that every component that's in a page adds to the viewstate size even if it's not rendered. So if you're trying to simulate dynamic loading of a large set of components into a page by using a hack something like this:
<apex:repeat value="{!componets}" var="component">
<customcomponet1 rendered="{!component == 'customcomponent1'}" />
<customcomponet2 rendered="{!component == 'customcomponent2'}" />
<customcomponet3 rendered="{!component == 'customcomponent3'}" />
</apex:repeat>
Some information about every single one of those components will be stored in the viewstate. You can see that if you use this technique in a component that's included mutlitple times with a large list in a page you can quickly use up the viewstate. I think this highlights the need for a real dynamic way of including components in a visualforce page. Here's one idea that I hope gets a lot more visibility:
http://ideas.salesforce.com/article/show/10097513/Custom_Component_Binding
I've also created an idea for releasing the debug tools for the viewstate:
http://ideas.salesforce.com/article/show/10098484/Release_Viewstate_Debug_Tools
I think a simple solution would be to allow developers to specify which components are included in the viewstate through a new attribute called includeInViewstate on components that behaves exactly like rendered except for the viewstate. I've created an idea but the viewstate doesn't seem to be an issue for most cases... :(
http://ideas.salesforce.com/article/show/10098627/Add_an_includeInViewstate_attribute_to_components
We are running into this Viewstate limit for our unit testing.
When I try to run all the unit tests via the 'Run All Tests' button found in Develop->Apex Classes, I have started getting the following message:
Maximum view state size limit (128K) exceeded. Actual viewstate size for this page was 150.625K
If we start deleting Unit tests, we will not be able to release a product.
I, too, am receiving this error. I'm creating a 'simple' HTML billing report for all of our accounts. I clear all of my maps and lists that I can before displaying the HTML, but it still goes past the 128KB mark (currently down to 130KB)
The report and controller are both pretty long, but the general layout of the VF page code is:
Report Parameters (2 date boxes and a button)
Report Totals (table with totals calculated in the controller)
Repeater of accounts that each can contain 3 datatables displaying each patient and their test counts for each test. Each account repeat also has the account totals at the bottom.
A Status Loader that contains a small rotating image and a label.
I've gotten past the 10k SOQL record limit. I've gotten past the 200k statement limit. Now I need to figure out how to get past this limit. (We have over 10k test records per month)
The 'standard' reporting feature of SF is great, but I could not see a way to get it to do what we are trying to do with this HTML. Any suggestions on how to reduce the state further?
Easiest way I know is to scrap the viewstate entirely by not using <apex:form> and just using straight <form> tags and handling binding yourself. Visualforce viewstate is worthless for anything but the simplest of use cases.
When you say use the <form> tag and handle the binding myself, does that allow for mutliple calls to the server side code?
What the page currently does is similar to this:
User enters a date range (1 month) and clicks submit
The form submits to the server and starts the querying process which is split into querying tests for each day (Query method call finishes and the page re-calls it until it has reached the last day) (10k record limit work-around)
After the querying is done, it organizes the data and calculates things that need calculating, all split into different calls ( BuildAccounts, BuildPatients, CalculateTotals, etc) (200k statement limit workaround)
The above items are stored in Maps and the final list of a custom class is stored in a List. The maps are cleared once the calculations are done and the List is built to reduce size.
Will this still work with a simple <form> tag? As far as I can tell, actionFunctions have to be contained in <apex:form> tags, and that is the only way I can see getting the above process working.
Any further help would be greatly appreciated!
After reading and testing some more, I set the final list of objects to be transient. That did the trick. The view state size goes up while calculating, then gets cleared out and displays the final results.
Hey,
I have been facing this error for a quite a while and i didn't find any solution for it.
Maximum view state size limit (135KB) exceeded
Here is my code, correct me where I went wrong. There is a button in another page, which upon clicked redirects to another page and here is that page codes.
Visualforce Page
<apex:page controller="Prospective_Attachment_AC" showHeader="true" standardStylesheets="false">
<head>
<script type="text/javascript">
function SelectFile( fileUrl )
{
// window.opener.SetUrl( url, width, height, alt);
parent.SetUrl( fileUrl ) ;
}
</script>
</head>
<apex:messages title="Errors Occured" styleClass="errorMsg" style="font-family:verdana,garamond,serif;" />
<br></br><br></br>
<apex:form >
<b><apex:outputLabel style="font-size:14px;" value="File" for="file"/></b>
<apex:inputFile id="fileToUpload" value="{!fileBody}" filename="{!fileName}" />
<apex:commandButton value="Save" action="{!upload}" />
<apex:commandButton action="{!cancel_upload}" value="cancel"/>
</apex:form>
<apex:pageBlock rendered="{!hasImage}" >
<img src="{!url}" width="200" height="160" />
<script>
this.onload = function()
{
SelectFile('{!url}');
}
</script>
</apex:pageBlock>
</apex:page>
Apex Controller
public with sharing class Prospective_Attachment_AC
{
public String LeadInfo_ID,ClientInfo_ID,DeleteLeadInfo_ID,EditLeadInfo_ID,Activity_ID,LeadActivity_ID,ConvertToClient_ID;
public String MailingmanagerAssigned,ManagementAdmin;
public string DuplicateLeadName,DuplicateEmail,DuplicateClient,DuplicateClientNumber;
public integer clientnumber = 0;
Manager_Activity__c MList = new Manager_Activity__c();
User uname,uname1 ;
User UserName = new User();
String LoggedUserName = UserInfo.getUserName();
String ProfineName = UserInfo.getName();
User MailingUser = [Select Name,Email,profile.Name,Manager.Email From User where Username =: LoggedUserName limit 1];
String New_ID;
public Prospective_Attachment_AC() /*Constructor*/
{
New_ID = System.currentPageReference().getParameters().get('Id');
mgnrInfo = [select id, Date__c,Manager_Associated__c,uploadcheck__c,Expectations__c,Activity_Discreption__c,Follow_Up__r.Lead_Name__c, Follow_Up__r.Lead_Manager__c,Follow_Up__r.User__c,Follow_Up__r.User__r.Name,Follow_Up__c from Manager_Activity__c where id=:New_Id];
ViewLeadsInfo = [select id, Lead_Name__c,User__r.Name,User__c,Company_Name__c,Last_Activity_Date__c,Phone_Number__c,Approached_Through__c,Lead_Manager__c,Website__c,Technology__c,Contact_Mail_ID__c,Lead_Description__c,Status__c,Start_Date__c,End_Date__c,ClientToLead__c,
Billing_City__c, Billing_Country__c, Billing_State__c, Billing_Street__c, Billing_Zip_Code__c, Shipping_City__c, Shipping_Country__c, Shipping_State__c, Shipping_Street__c, Shipping_Zip_Code__c from Lead_Info__c where id =: mgnrInfo.Follow_Up__c];
}
public Lead_Info__c ViewLeadsInfo = new Lead_Info__c();
public Lead_Info__c getViewLeadsInfo()
{
return ViewLeadsInfo;
}
public Manager_Activity__c ViewManagerActivity = new Manager_Activity__c();
public Manager_Activity__c getViewManagerActivity()
{
return ViewManagerActivity;
}
List<Lead_Info__c> LeadDetails_List = [select Lead_Name__c,User__r.Name,User__c,Contact_Mail_ID__c,Last_Activity_Date__c,Company_Name__c,Phone_Number__c,Approached_Through__c,Lead_Manager__c,Website__c,Technology__c,Lead_Description__c,Status__c,Start_Date__c,End_Date__c,
Billing_City__c, Billing_Country__c, Billing_State__c, Billing_Street__c, Billing_Zip_Code__c, Shipping_City__c, Shipping_Country__c, Shipping_State__c, Shipping_Street__c, Shipping_Zip_Code__c from Lead_Info__c order by CreatedDate desc];
public List<Lead_Info__c> getLeads_Info()
{
return LeadDetails_List;
}
List<Manager_Activity__c> ManagerActivity_List = [select id,Date__c,uploadcheck__c,Manager_Associated__c,Expectations__c,Activity_Discreption__c,Follow_Up__r.Lead_Name__c, Follow_Up__r.Lead_Manager__c,Follow_Up__r.User__c,Follow_Up__r.User__r.Name,Follow_Up__c from Manager_Activity__c where Follow_Up__c =: LeadInfo_ID order by CreatedDate asc];
public List<Manager_Activity__c> getManager_Activity()
{
return ManagerActivity_List;
}
public void ViewInfo()
{
Activity = true;
Leads_Table = true;
View_LeadsInfo = true;
HideNewLead_Button = true;
Enter_Activity = true;
ManagerActivity_List = [select id, Date__c,Manager_Associated__c,uploadcheck__c,Expectations__c,Activity_Discreption__c,Follow_Up__r.Lead_Name__c, Follow_Up__r.Lead_Manager__c,Follow_Up__r.User__c,Follow_Up__r.User__r.Name,Follow_Up__c from Manager_Activity__c where Follow_Up__c =:ViewLeadsInfo.id];
ViewManagerActivity.Date__c = System.Today();
ViewManagerActivity.Manager_Associated__c = ViewLeadsInfo.User__r.Name;
Map<String,String> attIdMap = new Map<String,String>();
Map<String,String> attNameMap = new Map<String,String>();
for(Attachment att : [select Id, ParentId, name from Attachment])
{
attIdMap.put(att.ParentId,att.Name);
attNameMap.put(att.ParentId,att.Id);
}
for(Manager_Activity__c ManagerAtt : ManagerActivity_List)
{
InnerClass ic =new InnerClass();
ic.ManageActRec = ManagerAtt;
//ic.AttName = attachmentName;
ic.AttName = attIdMap.get(ManagerAtt.Id);
ic.Attid = attNameMap.get(ManagerAtt.Id);
innerlist.add(ic);
}
}
public void ViewLeadsDetails()
{
LeadInfo_ID = System.currentPageReference().getParameters().get('LeadId');
ViewLeadsInfo = [select id, Lead_Name__c,User__r.Name,User__c,Company_Name__c,Last_Activity_Date__c,Phone_Number__c,Approached_Through__c,Lead_Manager__c,Website__c,Technology__c,Contact_Mail_ID__c,Lead_Description__c,Status__c,Start_Date__c,End_Date__c,ClientToLead__c,
Billing_City__c, Billing_Country__c, Billing_State__c, Billing_Street__c, Billing_Zip_Code__c, Shipping_City__c, Shipping_Country__c, Shipping_State__c, Shipping_Street__c, Shipping_Zip_Code__c from Lead_Info__c where id =: LeadInfo_ID];
if(ViewLeadsInfo.ClientToLead__c == true)
{
ConvertToClientButton = false;
ViewInfo();
}
else
{
ConvertToClientButton = true;
ViewInfo();
}
}
public Class InnerClass /*Inner Class */
{
public Manager_Activity__c ManageActRec{get;set;}
public String AttName{get;set;}
public String AttID{get;set;}
public Integer RecUniqId {get;set;}
}
Integer recCount = 1;
public List<InnerClass> Innerlist = new List<InnerClass>(); /* Inner Class List */
public List<InnerClass> getinnerlistRec()
{
return Innerlist;
}
public String attachmentName{get; set;}
Attachment attach_type = new Attachment();
Manager_Activity__c mgnrInfo = new Manager_Activity__c();
public transient Attachment att = new Attachment();
public string id;
public string fileName
{
get;set;
}
public Transient Blob fileBody
{
get;set;
}
public void upload()
{
mgnrInfo = [select id, Date__c,Manager_Associated__c,uploadcheck__c,Expectations__c,Activity_Discreption__c,Follow_Up__r.Lead_Name__c, Follow_Up__r.Lead_Manager__c,Follow_Up__r.User__c,Follow_Up__r.User__r.Name,Follow_Up__c from Manager_Activity__c where id=:New_Id];
Activity_ID = mgnrInfo.id;
uname1 = [select id, Name from User where Name=: mgnrInfo.Manager_Associated__c];
ViewLeadsInfo.Last_Activity_Date__c = System.Today();
update ViewLeadsInfo;
Activity = true; /*Boolean variable*/
User MailManager2 = [select id,Name,Email from User where Name=: mgnrInfo.Manager_Associated__c];
MailingmanagerAssigned = MailManager2.Email;
try
{
att = new Attachment();
att.Body = this.fileBody;
att.Name = this.fileName;
System.debug(att.Body+'&&&'+att.Name);
att.ParentId = Activity_ID;
this.fileBody = null;
insert att;
id = att.id;
attach_type = [select id,ParentId,Body, Name from Attachment where ParentId =: Activity_ID];
attachmentName = attach_type.Name;
InnerClass ic = new InnerClass();
ic.ManageActRec = MList;
ic.AttName = attachmentName;
ic.Attid = attach_type.id;
ic.RecUniqId = recCount;
recCount++;
innerlist.add(ic);
}
catch (DMLException e)
{
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
}
finally
{
att = new Attachment();
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully'));
AssignedManagerMail();
ManagerActivity_List = [select id, Date__c,uploadcheck__c,Manager_Associated__c,Expectations__c,Activity_Discreption__c,Follow_Up__r.Lead_Name__c,Follow_Up__r.Lead_Manager__c,Follow_Up__r.User__c from Manager_Activity__c where Follow_Up__c =:ViewLeadsInfo.id];
}
pagereference pageref3 = new pagereference('/apex/Prospective_Clients_VP');
public pagereference Cancel_upload() /* Cancel uploading the file */
{
Leads_Table = true;
Activity = true;
Enter_Activity = true;
View_LeadsInfo = true;
HideNewLead_Button = true;
pageref3.setRedirect(true);
return page.Prospective_Clients_VP;
}
/*Boolean Methods*/
public boolean Leads_Table{get; set;}
public boolean View_LeadsInfo{get; set;}
public boolean Activity{get; set;}
public boolean NewLeadInfo{get; set;}
public boolean HideNewLead_Button{get; set;}
public boolean Cancel_ViewLeadInfo{get; set;}
public boolean Edit_LeadDetails{get; set;}
public boolean Enter_Activity{get; set;}
public boolean ViewActivityInfo{get; set;}
public boolean ProjectDetails{get; set;}
public boolean ConvertToClientButton{get; set;}
public boolean hasImage {get; set;}
public boolean displayactivity {get; set;}
public String url {get; set;}
}
Best Regards
Make your attachment / document null at the end of method you are calling. The problem wilol get resolved.
Thank you dchasman,
It helps me to upload my file.
We got a solution for you…!
Here you may be interested in knowing about appexchange native app Cloud Drop which is having this feature.
For more details check:
http://www.clouddrop.io
Check Out the following URL for application:
https://appexchange.salesforce.com/listingDetail?listingId=a0N30000003IzEDEA0