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
Ashu sharma 38Ashu sharma 38 

Too many query rows 50001 in schedule class

Hi,

I have written an schedule class,in which when I run in production,it threw an error caused by: System.LimitException: Too many query rows: 50001

 line 25, column 1

 public void execute(SchedulableContext sc){
        
        list<lead> myFive9LeadList=[ select id,name,Originating_System__c,createdDate,Call_Center_Disposition_Date__c,Call_Center_Disposition_Details__c from lead where Originating_System__c='Five9' AND createdDate >:X15MinutesAgo];
        list<lead> mySparkroomLeadList=[ select id,name,Originating_System__c,createdDate from lead where Originating_System__c='Sparkroom' AND createdDate >:X15MinutesAgo];

//Line 25
        list<lead> myLeadListDispositions=[ select id,name,Originating_System__c,createdDate from lead where Call_Center_Disposition_Details__c='Transfer' AND Call_Center_Disposition_Date__c >:X15MinutesAgo];
        
        
        //For No Lead from Five9
        if(myFive9LeadList.size()==0 ){
            system.debug('Five9 List Size'+ myFive9LeadList.size());
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            mail.setToAddresses(toAddresses );
            mail.setCcAddresses(ccAddresses);
            mail.setSubject('Notification:: No Lead from Five9');
            String messageBody = '<html><body>Hi, &nbsp;&nbsp;&nbsp;</body> <br/> Last 15 minutes no lead generated from Five9.<br/>Please look into Five9 lead process and make sure that it is working fine.<br/><br/>Thanks </html>


Thanks..





 
Manj_SFDCManj_SFDC
Hi Ashu,

1) I think your prod org has more data, try adding more granular criteria in the where clause of the query, you can use count() to check the number of records in prod matching your where clause criteria

2) what is the batch size, try to keep it below 100 , for best practices you can refer

http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_gov_limits.htm (http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_gov_limits.htm" id="ext-gen31" rel="nofollow" style="font-family:DSCDefaultFontRegular; color:#048ec6 !important; text-decoration:none; font-weight:normal" target="_blank)
http://wiki.developerforce.com/page/Apex_Code_Best_Practices (http://wiki.developerforce.com/page/Apex_Code_Best_Practices" id="ext-gen28" rel="nofollow" style="font-family:DSCDefaultFontRegular; color:#048ec6 !important; text-decoration:none; font-weight:normal" target="_blank)
 
 


 
Ashu sharma 38Ashu sharma 38
Hi Manj_SFDC,

I am using only schdeule class on it,not batch class,directly schedule class i am using.But as per count size in my query its only fetched last 15 minutes in where clause,so I think its not crossing 50000 reocrds.

So should i use batch class over there.If I use batch class in my string query how should i write,because I have three different query on it.Any suggestion how to use batch class in it.

Thanks