+ Start a Discussion
Vigneshwaran LoganathanVigneshwaran Loganathan 

your request was running too long and has been stopped

I have a batch class in which I am deleting some records in Finish method. but its showing query error. can anyone help.? 

Not sure why the error is coming though i have set a limit to 9500 records. i can add more filters but need to know why this is not working.
global void finish(Database.BatchableContext bc) {
        // Delete TMs where the TOT has since been deleted, cancelled, rescheduled
        //delete [SELECT Id FROM Time_Management_AZ_EU__c WHERE TOT_For_Removal__c = TRUE];
        List <Time_Management_AZ_EU__c> Timemanage = new List<Time_Management_AZ_EU__c>(); 
        Timemanage = [SELECT Id, Name FROM Time_Management_AZ_EU__c WHERE TOT_For_Removal__c = TRUE LIMIT 9500] ;
         if(Timemanage.Size() > 0)
        Delete Timemanage;


NagendraNagendra (Salesforce Developers) 
Hi Vigneshwaran,

Each Apex transaction has a Maximum execution time of 10 minutes which is distinct from the Maximum CPU time per transaction on the Salesforce servers of 10,000 milliseconds for synchronous code and 60,000 milliseconds for asynchronous code. The 10-minute time limit exists to help prevent a thread from "hogging" server resources because the of the below limitation on what's counted towards CPU usage limits:

Operations that don’t consume application server CPU time aren’t counted toward CPU time. For example, the portion of execution time spent in the database for DML, SOQL, and SOSL isn’t counted, nor is waiting time for Apex callouts.

Note that the Maximum SOQL query run time before Salesforce cancels the transaction is 120 seconds.

One other possibility that could be impacting your tests is related to batch classes. Although only a single batch of 200 records are tested in a batch class, the production limits would still seem to apply. There are limits on the number of attempts and the time it takes to run the query for the batch class as follows: 15 attempts to process the query are allowed with a two minute limit on the time to process the query. There's a 5 min limit to process 100 records and a 10 min limit to process a batch before it's returned to the queue for later reprocessing. If it's returned more than 10 times, the batch is marked as failed. Max query retrieval size is 1Gb.

But if a server is running especially slow, any of the above possibilities for either a batch or the execution of long transaction would seem possible. More than anything, it sounds as though the limit on the Maximum execution time of 10 minutes per transaction is what's causing your problem.

See the documentation for more on  Thanks,