Salesforce | Maximum view state size limit (135KB) exceeded

|
| By Webner

We have a page in which we have to display more than 50000 records. Visualforce page has View state Limit set to 135 KB hence after reaching this Limit salesforce throws Exception as “Maximum view state size limit (135KB) exceeded”.

Solution: To resolve this issue we have used following approaches (pick the steps that apply to your situation):

1. Declare Variables as Transient to reduce the footprint of heavy data on the ViewState:

transient public Blob contentFile{get;set;}

2. Used Pagination on the page:

Retrieving only 20-50 records at a time. Using limit and offset in the query

‘SELECT Id,Name,RecordTypeId,MYAPP__CustomObj_Number__c,MYAPP__Effective_Date__c,MYAPP__CustomObj2__r.Name,MYAPP__CustomObjTypeCd__c,MYAPP__Account__r.MYAPP__Primary_Contact__c,MYAPP__CustomObj2_Product__c from MYAPP__CustomObj__c where MYAPP__To_be_Reviewed__c = true LIMIT :LimitSize OFFSET :OffsetSize’

Examining View State size for your page after making above improvements:

To enable the View State tab:

1. At the top of any Salesforce page, click the down arrow next to your name. From the menu under your name, select Setup or My Settings—whichever one appears.
2. From the left pane, select one of the following :

  • If you clicked Setup, select My Personal Information | Personal Information.
  • If you click My Settings, select Personal | Advanced User Details.

3. Click Edit.
4. Select the Development Mode checkbox if it isn’t selected.
5. Select the Show View State in Development Mode checkbox.
6. Click Save.

Following screenshot shows the list of pages with size:

2 comments

Leave a Reply

Your email address will not be published. Required fields are marked *