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
dwwrightdwwright 

Maximum view state size limit (128K) exceeded - Help?

I've run into a problem with one of my visualforce pages where I'm hitting this 128k viewstate size limit--I need some pointers on how to avoid it.

 

My page is used to display forms back to my users in a PDF. I've built the forms out in HTML tables with <apex: outputfield> components to display the data. My data structure is set up so that the user creates a Master Object, and then can create and number of child objects, which are the forms. Some of the forms have over 200 fields on them, but a requirement is that the user can display ALL forms they have filled out and print them in one page.

 

To accomplish this, I have an <apex:repeat> component on my page where the repeat variable is ALL the child records to this master object. This allows me to use the standard controller for the master object, then repeat through all the child objects and display their contents. I'm severely limited right now because once I create more than 5 forms, I start getting this viewstate error. I'm not using a custom controller, so I'm not really sure what I can do on my page to decrease this size, or handle it better. Please let me know if you have a solution!

Best Answer chosen by Admin (Salesforce Developers) 
jwetzlerjwetzler

Using apex:form implies that you have some information to submit, and thus it's going to store all of the (non-transient) data in viewstate.  Why are you using apex:form if all you are doing is displaying outputField?  I don't think it makes sense to use apex:form if you're using renderAs="pdf" as there is no input and nothing to submit.

All Answers

gv007gv007

Can you post some sample code that well help you.this error message seems the size of the displayed date limits exceeds for this in yours controller you need keep null values after displaying the date fields.After seeing yours sample code only I can tell you where you are missing.

 

This is know issue.

dwwrightdwwright

 

<apex:page standardController="Quality_Document__c" renderas="pdf">
	<head>
		<style type="text/css">
  			@page
  			{     			
    			@bottom-right {
      				content: "Page " counter(page);
    			}
  			}
  		</style>
	</head>
	 <apex:image url="{!$Resource.SRFLogo}" height="15%" width="15%" /> 
	<center><strong style="font-size:20px">Test Report</strong></center>
	<apex:form >
	<apex:pageBlock mode="edit">
               
        <!-- Sign off section, only displays when the Test Report Status is complete -->
		<apex:pageBlockSection columns="1" >
			<apex:outputText value="Digitally Signed for Quality Assurance" /><br/><apex:outputField value="{!Quality_Document__c.DigitalSignature__c}" />
		</apex:pageBlockSection> 
        <!-- First section of the page block /-->
        
        <apex:pageBlockSection title="Test Status" columns="1">

        <!-- Shows the overall status of this QD (Formula)  /-->
        <apex:outputField value="{!Quality_Document__c.Test_Report_Status__c}"/>

        <!--  Shows the SDQA completion status for this QD (Read Only Text)/-->
        <apex:outputField value="{!Quality_Document__c.SDQA_Completion_Status__c}"/>

        <!--  Shows the Micro Ohm validation status for this QD (Read Only Text) /-->
        <apex:outputField value="{!Quality_Document__c.Micro_Ohm_Status__c}"/>

        <!-- Shows the Contact Force validation status for this QD (Read Only Text) /-->
        <apex:outputField value="{!Quality_Document__c.Contact_Force_Status__c}"/>
        </apex:pageBlockSection>
        
        <apex:pageBlockSection title="Test Report Information" columns="1">
        
        <!-- Input for the name of this QD. (Text) /-->
        <apex:outputField value="{!Quality_Document__c.Name}" />
        
        <!-- Input for the customer of this QD (Lookup: Account) /-->
        <apex:outputField value="{!Quality_Document__c.Customer__c}"/>
        
        <!-- Input for sales order number (Text) /-->
        <apex:outputField value="{!Quality_Document__c.Sales_Order_Number__c}"/>
        
        <!-- Input for breaker serial number (Text) /-->
        <apex:pageBlockSectionItem />
        
        <!-- Sales line item number input (Text) /-->
        <apex:outputField value="{!Quality_Document__c.Sales_Line_Item_Number__c}"/>
        
        <!--  End first section of the page block/-->
        </apex:pageBlockSection>
                
        <!--Second section of the page block /-->
        <apex:pageBlockSection title="Breaker Selection" columns="1">
        
        <!-- "Select the Appropriate Breaker" (Picklist) /-->
        <apex:outputField id="breaker" value="{!Quality_Document__c.Breaker__c}"  />
        <!-- Wyle (Check Box) /-->    
        <apex:outputField value="{!Quality_Document__c.Wyle__c}"/>
        
        <!-- Input for Breaker Type (Text) /-->
        <apex:outputField value="{!Quality_Document__c.Breaker_Type__c}"/>
        
        <!-- UV Equipped (Check Box) /-->
        <apex:outputField value="{!Quality_Document__c.UV_Equipped__c}"/>

        <!-- Blank space /-->
        <apex:pageBlockSectionItem />
        
        <!-- Rework Status (Picklist)- Rendered if breaker is Rework /-->
        <apex:outputField rendered="{!Quality_Document__c.Breaker__c == 'Rework'}" value="{!Quality_Document__c.Rework_Status__c}"/>
        
        <!-- Replacement CB selection (Picklist) - Rendered if breaker is Replacement CB /-->
        <apex:outputField rendered="{!Quality_Document__c.Breaker__c == 'Replacement CB'}" value="{!Quality_Document__c.Retrofit_Breaker_Type__c}" />
        
        <!-- End second section of the page block /-->
        </apex:pageBlockSection>
                
        
        
        <!--3rd section of the page block 
         Doesn't render until a selection in "Select the Appropriate Breaker" is made /-->
        <apex:pageBlockSection title="Test Type Information" columns="1" rendered="{!Quality_Document__c.Breaker__c != null && Quality_Document__c.Breaker__c != 'SwitchGear' && Quality_Document__c.Breaker__c != 'Relay Panel'}">
        
        <!-- 3AF/3AH Type (Picklist) - Rendered once a breaker selection is made, unless the breaker is GMI /-->
        <apex:outputField value="{!Quality_Document__c.AF_AH_Type__c}"  rendered="{!Quality_Document__c.Breaker__c != 'GMI' && Quality_Document__c.Breaker__c != 'MAN GTD' && Quality_Document__c.Breaker__c != 'Switchgear' && Quality_Document__c.Breaker__c != 'Relay Panel' && Quality_Document__c.Breaker__c != 'Vacuum Bottle' && Quality_Document__c.Breaker__c != 'NXA'}"/>

		<!-- 3AK (Siemens Type for NXA Breakers only) -->
		<apex:outputField value="{!Quality_Document__c.Siemens_Type_NXA__c}"  rendered="{!Quality_Document__c.Breaker__c == 'NXA'}" />
                
        <!-- Vacuum Interrupter selection (Picklist) /-->
        <apex:outputField value="{!Quality_Document__c.Vacuum_Interrupter__c}"  rendered="{!Quality_Document__c.Breaker__c != 'MAN GTD'}" />
                
        <!-- Voltage selection (Picklist) /-->
        <apex:outputField value="{!Quality_Document__c.Voltage__c}"  rendered="{!Quality_Document__c.Breaker__c != 'Vacuum Bottle' && Quality_Document__c.Breaker__c != 'NXA'}" />
        
        <!-- Voltage selection for NXA (Picklist) -->
		<apex:outputField value="{!Quality_Document__c.NXA_Voltage__c}"  rendered="{!Quality_Document__c.Breaker__c == 'NXA'}" />
        
        <!-- Close & Latch selection (Picklist) - Rendered unless breaker is Manual/Electric Ground & Test Device /-->
        <apex:outputField value="{!Quality_Document__c.Close_Latch_RMS_Peak__c}"  rendered="{!Quality_Document__c.Breaker__c != 'E-O GTD' && Quality_Document__c.Breaker__c != 'Vacuum Bottle' && Quality_Document__c.Breaker__c != 'MAN GTD'}"/>
              
        <!-- MVA selection display (Picklist) /-->
        <apex:outputField value="{!Quality_Document__c.MVA__c}"  rendered="{!Quality_Document__c.Breaker__c != 'Vacuum Bottle'}"/>
        
        <!-- AMPS selection display (Picklist)  /-->
        <apex:outputField value="{!Quality_Document__c.Amps__c}"   rendered="{!Quality_Document__c.Breaker__c != 'E-O GTD' && Quality_Document__c.Breaker__c != 'MAN GTD' && Quality_Document__c.Breaker__c != 'Vacuum Bottle'}" />
        
        <!-- Displays Name of Matching Test Type -->
        <apex:outputField value="{!Quality_Document__c.Test_Type_Display__c}" rendered="{!Quality_Document__c.Breaker__c != 'Vacuum Bottle' && Quality_Document__c.Breaker__c != 'NXA' && Quality_Document__c.Breaker__c != 'Relay Panel' && Quality_Document__c.Breaker__c != 'SwitchGear'}" />
        
        <!-- End of third section of the page block /-->
        </apex:pageBlockSection>
        
    <!-- End of page block /-->    
    </apex:pageBlock>

	
	<apex:repeat value="{!Quality_Document__c.SDQAs__r}" var="S">

	<p style="page-break-before: always"/>
	
	<apex:image url="{!$Resource.SRFLogo}" height="15%" width="15%" />
	
	<apex:output Panel rendered="{!S.Name == 'SDQA 178'}" >
		(Content of my forms go in here. There are 24 outputpanels on the page and the appropriate one displays based on the name of the child object currently being iterated over.)
	</apex:outputPanel>
	....more <apex:outputPanel>......


	</apex:repeat> 

 

jwetzlerjwetzler

Using apex:form implies that you have some information to submit, and thus it's going to store all of the (non-transient) data in viewstate.  Why are you using apex:form if all you are doing is displaying outputField?  I don't think it makes sense to use apex:form if you're using renderAs="pdf" as there is no input and nothing to submit.

This was selected as the best answer
Ron HessRon Hess

I know it sounds strange , but i've seen this error when my org was > 100% data storage capacity, i had been uploading files all day, and then my page hit this message, i had no ability to create records or upload any attachments.

 

once i cleared some data space this message went away.

 

 

dwwrightdwwright

Jill,

Thank you so much! I was using <apex:form> tags because I was displaying some of the fields in an <apex: selectList> component (this is because I copy/pasted the code from a non pdf version of the page). I changed them all to outputField and took off the form tags, and I'm good to go =) 

Nick_SimhaNick_Simha

Please also see this article that delves into View state, the new view state inspector in Summer '10 and finally best practices to optimize view state.

 

http://wiki.developerforce.com/index.php/An_Introduction_to_Visualforce_View_State

 

 

jhonnikol sonjhonnikol son
this topic will be helpful for everyone, thanks alot for this.
neato botvac review (https://cleaningbeasts.com/neato-botvac-connected-review/)