0

One of our VF page is based on a REST web-service which retrieves Service requests from Siebel in real-time. When number of records exceeds 1000, we were receiving below error because of which i added 'readonly' attribute in VF page component. 'Content cannot be displayed: Collection size 1,582 exceeds maximum size of 1,000'

Now we are getting view state error. And 'Internal' is occupying 210kb so not sure which ones I can make Transient. ViewState

I went through a post about this but didn't quite understand that. Below code is from Controller class, please help.

public class AccountServiceControllerExtension2 {

    public final Account acct{get; Set;}
    public String siebelId{get; set;}
    public String requestBody{get; set;}
    public String requestResult{get; set;}

    public list<list<String>> mainList{get; set;}
    public String pageUrl{get;set;}

    public Transient list<list<list<String>>> allList{get;set;}
    public list<list<String>> temp;
    public list<String> dataList1;
    public list<String> dataList2;
    public list<String> dataList3;
    public list<String> dataList4;
    public list<String> dataList5;

    public AccountServiceControllerExtension2(ApexPages.StandardController stdController) {
        this.acct = (Account)stdController.getRecord();
        pageUrl = URL.getSalesforceBaseUrl().toExternalForm()+'/apex/ServiceRequest2?id='+acct.id;


        List<Account> siebelIdLs=[select Siebel_Row_ID__c from Account where Id=:acct.id limit 1];
        siebelId='';
        if(siebelIdLs.size()==1)
        {
            if(siebelIdls.get(0).Siebel_Row_ID__c!=''&&siebelIdls.get(0).Siebel_Row_ID__c!=null){
                siebelId=siebelIdls.get(0).Siebel_Row_ID__c;
            }
        }

        String requestUrl='https://esbintg-m1.nit.oclc.org/services/getServiceRequest';

        String result='';
        Transient List<String> mresult = new List<String>();
        if(siebelId!='')
        {
            AccountHttpRequest ahr=new AccountHttpRequest();
            mresult=ahr.postCall(requestUrl,siebelId);
            if(mresult[0] == 'Success') 
            { 
                result = mresult[1];
                Transient List<map<String,String>> mapList=parseJason(result);   //get list data from json response
                if(mapList.size()>0)
                {
                    list<WebRequestMapListWrapper> wrapperList=new list<WebRequestMapListWrapper>();   

                    for(Integer i=0;i<mapList.size();i++){
                        WebRequestMapListWrapper wrapper1=new WebRequestMapListWrapper(mapList.get(i));
                        wrapperList.add(wrapper1);
                    }
                    wrapperList.sort();

                    mapList=new List<map<String,String>>();
                    //reverse order
                    for(Integer i = wrapperList.size()-1; i>=0;i--){
                        mapList.add(wrapperList.get(i).dataMap);
                    }
                }
                else
                {
                    requestResult='No data for this account.';
                }


                allList=new List<list<list<String>>>();     //Top level list for all rows
                list<String> dataList1=new List<String>();

                for(Integer i=0;i<mapList.size();i++)
                {
                    temp=new List<list<String>>();
                    dataList1=new List<String>();          //Bottom level list for real data
                    temp.add(dataList1);                  
                    allList.add(temp); 

                    if(mapList.get(i).get('abstract')==null) mapList.get(i).put('abstract','');
                    .
                    .
                    <code which Gets and Adds to the List>
                    .
                    .

                    dataList1.add('pageBlockTable'+String.valueOf(i)); //No.14

                }
            }       
            else
            { 
                requestResult = mresult[1];
            }
        }
        else
        {    requestResult='No Siebel Row ID.';
        }
    }   


    public list<map<String,String>> parseJason(String result)
    {   
        Map<String, String> amap=new Map<string, String>();

        List<map<String,String>> mapList=new List<map<String,String>>();
        if(result==''||result==null){
            return mapList;
        }

        Map<String, String> tempMap;

        JSONParser parser = JSON.createParser(result);
        boolean flag=false;

        while (parser.nextToken() != null) {


            if ((parser.getCurrentToken() == JSONToken.FIELD_NAME)){
                String fieldName = parser.getText();


                if(flag){
                    if(fieldName=='abstract'){
                        tempMap = new Map<String, String>();
                        mapList.add(tempMap);
                        parser.nextToken();
                        tempMap.put('abstract',parser.getText());
                    }
                    .
                    .
                    <Statements which parses each token>
                    .
                    .
                }


                if(fieldName=='serviceRequest'){
                    flag=true;     
                    //System.debug('----------');
                }

            }

        }

        return mapList;

    }       
}

And my VF Page

<apex:page standardController="Account" extensions="AccountServiceControllerExtension2" readOnly="true" id="page">

    <style type="text/css">        

       .vfTableMainInfo {
            table-layout:fixed;
            word-wrap:break-word;
            overflow:hidden; 
            width: 50px;

        }

        .vfTable {
            table-layout:fixed;
            word-wrap:break-word;
            overflow:hidden; 
            width: 50px;

        }

        .expandFoldText{
            color: rgb(1,91,167);           
        }
        .expandFoldText1{
            color: rgb(1,91,167);           
        }       
        .expandFoldText2{
            color: rgb(1,91,167);    
            display: none;       
        }


    </style>


    <apex:form id="form">

    <apex:pageBlock id="main1" title="Service Data">    
              <apex:repeat id="repeat" value="{!allList}" var="innerList">

        <apex:pageBlockTable id="subTable1" value="{!innerList}" var="item" styleClass="vfTable">        



             <apex:column >

                     <label id="plus{!innerList[0][14]}" class="expandFoldText1" onmouseover="componentColorMouseOver(this);"  onmouseout="componentColorMouseOut(this);" onclick="expandProudct1(this,{!innerList[0][14]});" >(+)</label>
                     <label id="minus{!innerList[0][14]}" class="expandFoldText2" onmouseover="componentColorMouseOver(this);"  onmouseout="componentColorMouseOut(this);" onclick="expandProudct2(this,{!innerList[0][14]});">(-) </label>

                     {!item[0]}
                    <apex:facet name="header">                        
                       <label>Product</label>
                    </apex:facet> 
             </apex:column>


             <apex:column value="{!item[1]}">

                    <apex:facet name="header">Status</apex:facet>

             </apex:column>
             <apex:column value="{!item[2]}">
                    <apex:facet name="header">Abstract</apex:facet>
             </apex:column>
             <apex:column value="{!item[3]}">
                    <apex:facet name="header">Date Open</apex:facet>
             </apex:column>

        </apex:pageBlockTable>     


        <div id="{!innerList[0][14]}" style="display:none">

        <apex:pageBlockTable id="subTable2" value="{!innerList}" var="item" styleClass="vfTable">               
             <apex:column >
                    <apex:facet name="header"></apex:facet>
             </apex:column>       
             <apex:column value="{!item[4]}">
                    <apex:facet name="header">Name</apex:facet>
             </apex:column>
             <apex:column value="{!item[5]}">
                    <apex:facet name="header">SR Number</apex:facet>
             </apex:column>
             <apex:column value="{!item[6]}">
                    <apex:facet name="header">Date Closed</apex:facet>
             </apex:column>                           
        </apex:pageBlockTable>       

        <apex:pageBlockTable id="subTable3" value="{!innerList}" var="item" styleClass="vfTable">               
             <apex:column >
                    <apex:facet name="header"></apex:facet>
             </apex:column>       
             <apex:column value="{!item[7]}">
                    <apex:facet name="header">Resolution</apex:facet>
             </apex:column>
             <apex:column value="{!item[8]}">
                    <apex:facet name="header">Owner</apex:facet>
             </apex:column>
             <apex:column value="{!item[9]}">
                    <apex:facet name="header"></apex:facet>
             </apex:column>                           
        </apex:pageBlockTable> 


        </div>


        </apex:repeat>        
    </apex:pageBlock>

    </apex:form>

    <script>


          function hideAllHeader(){
            var headerList=document.getElementsByClassName("headerRow");
            tableList=document.getElementsByTagName("table");
            var aTable;                        
            var headers;

            var test=tableList[3];


          for (var i = 0; i < tableList.length; i++) {
            if((tableList[i].id!=="page:form:main1:repeat:0:subTable1")&&(tableList[i].id.indexOf("page:form:main1:repeat:")===0)){           
                headers=tableList[i].getElementsByTagName("thead");                
                for(var j =0; j<headers.length; j++){
                    headers[j].style.display="none";  
                }
               }                                            
            }
         }

         hideAllHeader();      

   </script>


    <script>
         window.onload = function(){
             hideAllHeader();               
         };   



         function componentColorMouseOver(component){
             //component.style.color="rgb(1,91,167)";
             component.style.color="red";
         }

         function componentColorMouseOut(component){
             //component.style.color="black";
             component.style.color="rgb(1,91,167)";
         }


         function expandProudct1(t, div){

             var headerId=div.id.replace("pageBlockTable","page:form:main1:repeat:"); //page:form:main1:repeat:0:subTable1
             var headerId1=headerId+":subTable1";
             var headerId2=headerId+":subTable2";

             var headerId3=headerId+":subTable3";

             var tableElem1=document.getElementById(headerId1);
             var headersElem1=tableElem1.getElementsByTagName("thead"); 
             var tableElem2=document.getElementById(headerId2);
             var headersElem2=tableElem2.getElementsByTagName("thead"); 
             var tableElem3=document.getElementById(headerId3);
             var headersElem3=tableElem3.getElementsByTagName("thead"); 


             var curDisplay=String(div.style.display);
             if(curDisplay==='none'){             
                 //expand/fold table
                 div.style.display="inline";        

                 t.style.display="none"; //hide/display plus and minus sine                 
                 document.getElementById(t.id.replace("plus","minus")).style.display="inline";    //hide/display plus and minus sine

                 //expand/fold table header
                 if(headerId1.indexOf("page:form:main1:repeat:0:subTable1")===-1){
                     for(var x1 =0; x1<headersElem1.length; x1++){
                         headersElem1[x1].style.display="table-row-group";  
                     }
                 }    
                 for(var x2 =0; x2<headersElem1.length; x2++){
                     headersElem2[x2].style.display="table-row-group";  
                 }  
                 for(var x3 =0; x3<headersElem1.length; x3++){
                     headersElem3[x3].style.display="table-row-group";  
                 }  

             }    

         }


         function expandProudct2(t, div){

             var headerId=div.id.replace("pageBlockTable","page:form:main1:repeat:"); //page:form:main1:repeat:0:subTable1
             var headerId1=headerId+":subTable1";
             var headerId2=headerId+":subTable2";
             var headerId3=headerId+":subTable3";

             var tableElem1=document.getElementById(headerId1);
             var headersElem1=tableElem1.getElementsByTagName("thead"); 
             var tableElem2=document.getElementById(headerId2);
             var headersElem2=tableElem2.getElementsByTagName("thead"); 
             var tableElem3=document.getElementById(headerId3);
             var headersElem3=tableElem3.getElementsByTagName("thead"); 

             var curDisplay=String(div.style.display);            
             if(curDisplay=='inline'){
                 div.style.display="none";
                 t.style.display="none"; 
                 document.getElementById(t.id.replace("minus","plus")).style.display="inline";   


                 //expand/fold table header

                 if(headerId1.indexOf("page:form:main1:repeat:0:subTable1")===-1){
                     for(var x1 =0; x1<headersElem1.length; x1++){
                         headersElem1[x1].style.display="none";  
                     }
                 }
                 for(var x2 =0; x2<headersElem1.length; x2++){
                     headersElem2[x2].style.display="none";  
                 }  
                 for(var x3 =0; x3<headersElem1.length; x3++){
                     headersElem3[x3].style.display="none";  
                 } 

             }      

         }
         function displayAllColumns(){
             document.getElementById("pageBlock1").style.display="none";    
             document.getElementById("pageBlock2").style.display="inline";    
         }

         function displayMainColumns(){
             document.getElementById("pageBlock2").style.display="none";    
             document.getElementById("pageBlock1").style.display="inline";    
         }

    </script>
</apex:page>

Service Requests are displayed like this. SRs

3

The “internal” is overhead from the Visualforce apex:tags; the convenience of those tags comes at the cost of quite quickly consuming the available view state. Using plain HTML instead for the table rows is one workaround.

PS

If you open the page and use your browser's "View Page Source" option and search in that text you will find a hidden field with the name com.salesforce.visualforce.ViewState. That is the view state that can't exceed the 135k limit (in it's server-side representation).

As your page doesn't have any input fields, removing the <apex:form> and </apex:form> tags will not affect the pagfe's functionality and will stop the view state from needing to be created and so stop the error whatever the number of rows is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.