+ Start a Discussion
OSJMgrOSJMgr 

Another Maximum View State Size Error - Please Help!

Hi All:

 

I receive the following error when I click on a commandbutton in a visualforce page that calls another page to execute Apex code:

 

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

 

The wierd thing is, is that it works fine in the Sandbox, but not in production.

 

There are a couple of other posts regarding this issue, however, they specifically address trying to attach a file via a visualforce page.  I am not trying to do that.  I just have a very large page that includes a tabpanel.  On the conclusion tab, I include a list of child records with the ability to conduct inline editing using the apex:repeat tag and a controller that uses a SOQL statement to return the records.

 

Please Help!

 

Here is an excerpt of the code:

 

 

 

public class supissuesController {
 // class variables
 Inspection__c insp;
 Supervisory_Issue__c[] supissue; 
 public String strID = 'unset';
 
 public supissuesController() {
    }
    
  
 public supissuesController(ApexPages.StandardController controller) {
     this.insp = (Inspection__c)controller.getSubject();
     
     System.Debug('DEBUG: CALLING CONSTRUCTOR');
     this.supissue = [ SELECT 
      SystemModstamp, Name, 
      LastModifiedDate, LastModifiedById, LastActivityDate, 
      IsDeleted, Id, CreatedDate, CreatedById, 
      Category__c, Type__c, Issue_Notes__c, Follow_up_Type__c, 
      Follow_up_Notes__c, Status__c, Resolution_Type__c,Resolution_Date__c ,Referred_to_FFS_Compliance__c,
      Notes_to_Compliance__c
      FROM 
      Supervisory_Issue__c
      WHERE 
      Inspection__c = :insp.id 
      ORDER BY Category__c ASC];
     
      }
 
 // Action Method called from page button
 public pagereference saveChanges() { 
  upsert this.supissue;
  return null;
  }
 
 public PageReference  getstrID() {
     PageReference pageRef = ApexPages.CurrentPage();
     pageRef.getParameters().put('strID', strID );   
     return pageRef ;     
     }
     
 // Action Method called from page link
 public pagereference newSupervisoryissue() { 
  Supervisory_Issue__c d = new Supervisory_Issue__c();
  d.Inspection__c =this.insp.id; 
  supissue.add( d );
  return null;
 }
 
 // public Getter to provide table headers 
 public string[] getheaders() { return new string [] 
  {'Name', 'Category','Type', 'Issue Notes',
   'Follow-up Type', 'Follow-up Notes', 'Issue Status','Resolution Type','Closed Date',
    'Refer Compliance?','Compliance Notes' } ; }
 
 // public Getter to list related supervisory issues
 public Supervisory_Issue__c[] getSupervisoryissue() { 
  return this.supissue; 
 } 
     
  public pageReference  CallInsertClass() {    
     String strPage = '/apex/CallInsertClass?';
     ID InspID = System.currentPageReference().getParameters().get('id');
     Inspection__c insp  = [select RR_DM__c from Inspection__c where ID = :InspID LIMIT 1];     
     
     strPage += 'InspID=' + InspID;
     strPage += '&ContID=' + insp.get('RR_DM__c');
     
     Pagereference  midPage = new Pagereference(strPage);    
     midPage.setredirect(true);
    
     return midPage ;     
     }  
 
 public pageReference InvokeNewRcdCreator    () {
     Inspection__c[] Insp_recs= new List<Inspection__c>();
     ID InspID = System.currentPageReference().getParameters().get('InspID');
     ID ContID = System.currentPageReference().getParameters().get('ContID');
     ID RRID;

     String strSOQL;
     Schema.DescribeFieldResult InspFld;
     Integer FldCount = 1;     
     String strPage = '/apex/rrbydminsp?id='+InspID;
     Schema.DescribeSObjectResult InspResult;
     
     Map<String, Schema.SObjectField> InspMap = new Map<String, Schema.SObjectField>();
     InspMap = Schema.SObjectType.Inspection__c.fields.getMap(); 
     
     List<Schema.SObjectField> InspList = InspMap.values() ;     
     
     System.Debug('InspID: ' + InspID );
     System.Debug('PAGEREF: ' + System.currentPageReference().getURL());
         
     String strInsp_flds = '';

     InspFld= InspList.get(0).getDescribe();                
     strInsp_flds = InspFld.getName(); /// build the first one....
     for( Integer i = 1 ; i < InspList.size() ; i++ ){
        InspFld= InspList.get(i).getDescribe();                
        strInsp_flds += ','+InspFld.getName();
        FldCount++;        
        }    
             
     //DEBUG
     //InspID = 'a0ES0000001BM6v';
     strSOQL = 'SELECT ' + strInsp_flds + ' FROM Inspection__c WHERE Id=\''+InspID+'\' LIMIT 1';
     System.debug('SOQL for Inspection__c : ' + strSOQL );
     
     Insp_recs= Database.query(strSOQL );
     RRID = Insp_recs[0].RR_DM__c;
     Contact dummyCont  =[select OwnerID  from Contact  where ID = :RRID  LIMIT 1];
     RRID = dummyCont.OwnerID;
     Supervisory_Issue__c sup_issue ;
     
     //
     // START CREATING RECORDS
     //     
     /// first:   Create a Supervisory record and start working on it....
     integer RcdsCreated = 0;     
       
     if (Insp_recs[0].RRDMUnrslvdDef__c == True) {
          sup_issue = Init_SupRcd(InspID, ContID, RRID);          
          sup_issue.Issue_Notes__c = 'Issues from previous inspection' ;
          sup_issue.Issue_Notes__c += ' were not resolved by current inspection. ';
          sup_issue.Issue_Notes__c += ' Noted by DM during the RRs ';
          sup_issue.Issue_Notes__c += Insp_recs[0].Inspection_Year__c; 
          sup_issue.Issue_Notes__c += ' inspection conducted on ';
          sup_issue.Issue_Notes__c += Insp_recs[0].Inspection_Date__c;
          sup_issue.Issue_Notes__c += '. See hardcopy inspection checklist ';
          sup_issue.Issue_Notes__c += 'or contact the ROSJ for additional details. ';
          sup_issue.Issue_Notes__c += 'Details: ' + Insp_recs[0].RRDMUnrslvdDefNotes__c;                             
            
          if(Insp_recs[0].Inspection_Date__c != null) {
              sup_issue.Event_Date__c = Insp_recs[0].Inspection_Date__c;
              }
        
          if(Insp_recs[0].Date_Reviewed__c != null) {
              sup_issue.Date_Reported__c = Insp_recs[0].Date_Reviewed__c;
              }
        
          sup_issue.Category__c =  'Inspection';
          sup_issue.Type__c =  'Unresolved Inspection Deficiencies';
          sup_issue.How_Discovered__c =  'Office Inspection';
          sup_issue.Discovered_By__c =  'District Manager';
          sup_issue.Status__c =  'Closed';
          sup_issue.Follow_up_Type__c = 'Other';
          sup_issue.Resolution_Type__c = 'Other';
          sup_issue.Resolution_Date__c = Date.today();
          insert sup_issue;
          RcdsCreated++;
          } //repeats several times
///
     /// -- Logical end of Controller -- now do cleanup     
     ///Insp_recs[0].DebugCnt__c = RcdsCreated;
     //return(RcdsCreated);
            
     strPage  = strPage + '&rcds=' + RcdsCreated;
     Pagereference  lastPage = new Pagereference(strPage); 
     ///System.debug('REDIRECT page: ' + strPage);
     lastPage.setredirect(true);

     return lastPage ;          
     }
 
 public Supervisory_Issue__c Init_SupRcd(ID InspID, ID ContID, ID RRID) {
     Supervisory_Issue__c sup_issue = new Supervisory_Issue__c();
     sup_issue.Inspection__c = InspID;
     sup_issue.DM_RR__c = ContID ;
     sup_issue.Assigned_To__c = RRID;     
     return sup_issue;
     }
     
 public integer BoolCheck(boolean bChkVal) {
  integer retVal = 0;
  if (bChkVal == True) 
      retVal = 1;
  return retVal;
  }

}
 
bob_buzzardbob_buzzard

The viewstate contains information to maintain state between requests, so if you are exceeding the limit it implies you have a lot of data being retained across requests.

 

I'd surmise that the cause of this is your list of supervisory issues.  If you only experience the error in production, then it sounds like your query is returning more data in production than the sandbox. 

 

You probably want to look at pagination here - limit the number of records displayed on a single page and allow the user to navigate through them via next/prev buttons.