Thursday, May 3, 2012

Maximum view state size limit exceeded in Salesforce

Error : Maximum view state size limit (135KB) exceeded. Actual view state size for this page was 410.891KB.  

Step 1:
This will occurs when the variable is u declared as a public .So try to declare this variables as transient. Because this transient keyword used to declare instance variable that cannot be saved.

Step 2:
Open the view state and check which variable it taking the kilobytes, see if you can set that variable to null after rendering the page.
You have to enable view state from your personal information if its already not enabled.

If you edit your profile, there are two checkboxes - "development mode" and "show view state in development mode".  If you check both of these, you will have access to the view state inspector.  However, if you are already exceeding the view state it may not be much help - you might need to reduce it before you can see it properly if you get  my meaning.  

Step 3:
Example:
You will be using a variable to hold file data like this.
VF Page:
<apex:inputFile value="{!file}"/>

In Apex class:
public blob file{get; set;}

Use transient keyword before blob data type. like below,

public transient blob file{get; set;}

The transient keyword gives persistency in the VF page..

Reference:

No comments:

Post a Comment