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
gyani19901.3956550919266765E12gyani19901.3956550919266765E12 

Time Limit Exceed error in visualforce page

Hi All,
I have written a apex class and vf page ,like

Apex Code:
public class dashboardcontrollerFor30Days
{
    public list<innerdashdata> data{get;set;}
    public list<task> tsklist;
    public list<AggregateResult> tsklist2;
    public list<AggregateResult> tsklist3;
    public map<id,integer> countmap;
    public map<id,integer> countmap2;
    public map<id,integer> countmap3;
    public map<id,integer> countmap4;
    public map<id,map<string,integer>> mapofdata = new  map<id,map<string,integer>>();
    public list<event> evntlist;
    public dashboardcontrollerFor30Days()
    {
        Set<String> names = new Set<String>{'%ABC%'};
        Set<String> names2 = new Set<String>{'Call','Added to Case from Contacts','CourtLink Lead','Data Entry Request','Dogsheet Lead','Email','Gift','Research Request'};        
        tsklist = new list<task>();
        evntlist = new list<event>();
        countmap = new map<id,integer>();
        countmap2 = new map<id,integer>();
        countmap3 = new map<id,integer>();
        countmap4 = new map<id,integer>();
       
        tsklist = [select ownerid,id,status from task where (not subject like '%mass%') and (not subject like '%DFW Survival Football Pool %') and (not owner.name like:names) and type =:names2 and (status ='1. Completed - PHONE CALL' OR status ='2. Completed - LEFT MESSAGE' OR status ='3. Completed - SENT EMAIL' )  and lastmodifieddate = LAST_N_DAYS:30];
     
     for(task tk : tsklist )
     {
         if(!mapofdata.keyset().contains(tk.ownerid))
         {
             mapofdata.put(tk.ownerid,new map<string,integer>());
         }
         if(!mapofdata.get(tk.ownerid).keyset().contains(tk.status))
         {
             mapofdata.get(tk.ownerid).put(tk.status,0);
         }
        integer count =  mapofdata.get(tk.ownerid).get(tk.status)+1;
        mapofdata.get(tk.ownerid).put(tk.status,count );
     }
      system.debug('********************'+mapofdata);
     
     
     
        
         data = new list<innerdashdata>();
         map<id,user> usermap = new map<id,user>([select id,name from user where isactive = true]);
      
        for(string str : mapofdata.keyset())
        {
             integer counttotal =  (mapofdata.get(str).get('1. Completed - PHONE CALL')!=null?mapofdata.get(str).get('1. Completed - PHONE CALL'):0) + (mapofdata.get(str).get('2. Completed - LEFT MESSAGE')!=null?mapofdata.get(str).get('2. Completed - LEFT MESSAGE'):0) + (mapofdata.get(str).get('3. Completed - SENT EMAIL')!=null?mapofdata.get(str).get('3. Completed - SENT EMAIL'):0);
             system.debug('**************************'+counttotal );
             data.add(new innerdashdata(mapofdata.get(str).get('1. Completed - PHONE CALL')!=null?mapofdata.get(str).get('1. Completed - PHONE CALL'):0,mapofdata.get(str).get('2. Completed - LEFT MESSAGE')!=null?mapofdata.get(str).get('2. Completed - LEFT MESSAGE'):0,mapofdata.get(str).get('3. Completed - SENT EMAIL')!=null?mapofdata.get(str).get('3. Completed - SENT EMAIL'):0,usermap.get(str).name+' '+ string.valueof(counttotal)));
        }
         system.debug('***************countmap'+data);
        
        
             
    }

    public class innerdashdata
    {
    public string name{get;set;}
    public decimal data1{get;set;}
    public decimal data2{get;set;}
    public decimal data3{get;set;}
    public string total{get;set;}
   
        public innerdashdata(decimal  data1,decimal data2,decimal data3,string name)
        {
            this.data1 = data1;
            this.data2 = data2;
            this.data3 = data3;
            this.name = name;
            
        }
    }

}


===== vf page 



<apex:page controller="dashboardcontrollerFor30Days" showHeader="false" sidebar="false" cache="false">

<div style="width:255px; height:460px;background-color:#E8E8FF;">
  <apex:chart data="{!data}" height="460" width="250">
    <apex:axis type="Numeric" position="bottom" title="Count" fields="data1,data2,data3" dashSize="2">
        <apex:chartLabel />
    </apex:axis>
    
    <apex:axis type="Category" position="left" fields="name" title="Assigned" >
        <apex:chartLabel />
    </apex:axis>
       
    <apex:barSeries orientation="horizontal" axis="left" stacked="true" 
        yField="name" xField="data1,data2,data3" title="Completed - PHONE CALL,Completed - LEFT MESSAGE,Completed - SENT EMAIL" />
  </apex:chart>
  <hr/>
    <table style="background-color:#E8E8FF;width:255px;">
        <tr>
            <td>
                <img src="{!$Resource.Blue}" style="margin-left:50px;"/>
            </td>
            <td>
                Completed - PHONE CALL 
            </td>
        </tr>
        <tr>
            <td>
                <img src="{!$Resource.Orange}" style="margin-left:50px;"/>
            </td>
            <td>
                Completed - LEFT MESSAGE 
            </td>
        </tr>
        <tr>
            <td>
                <img src="{!$Resource.Green}" style="margin-left:50px;"/>
            </td>
            <td>
                Completed - SENT EMAIL  
            </td>
        </tr>
    </table>           
</div>

</apex:page>



in this code i got an error 'Time Limit Exceed' and page take lots of time on loading. So Please help me , how can i remove this error.
 
Frédéric TrébuchetFrédéric Trébuchet
Did you try your "SELECT" alone?
What has happened?
How many rows is there in your "TASK" object?

Regards,
Fred
gyani19901.3956550919266765E12gyani19901.3956550919266765E12
Thanks for your reply, in this there are around 10,000 records , and after use select as alone , again got the same error.
gyani19901.3956550919266765E12gyani19901.3956550919266765E12
Number of SOQL queries: 2 out of 100 *Number of query rows: 3158 out of 50000* Number of SOSL queries: 0 out of 20 Number of DML statements: 0 out of 150 Number of DML rows: 0 out of 10000 *Maximum CPU time: 263 out of 10000* Maximum heap size: 0 out of 6000000 Number of callouts: 0 out of 100 Number of Email Invocations: 0 out of 10 Number of future calls: 0 out of 50 Number of queueable jobs added to the queue: 0 out of 50 Number of Mobile Apex push calls: 0 out of 10 this is the query rows and the cpu time
BalajiRanganathanBalajiRanganathan
Since you dont have any form in your VF, you have to have use readonly mode so that Salesforce allow you to show more rows in your result.

 Set readOnly to true in apex:page
<apex:page controller="SummaryStatsController" readOnly="true">

https://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_readonly_context_pagelevel.htm


 
Frédéric TrébuchetFrédéric Trébuchet
what if you replace "type = :names2" by "type IN :names2"?
gyani19901.3956550919266765E12gyani19901.3956550919266765E12
I have done the same change, but the issue are the same.