0

I have a schedulable batch class which is stateful. In execute am inserting upto 1000 records.

In final method i have a list of ids of inserted record

global void finish(Database.BatchableContext BC)
  {
                    if(Ids.size()>0)
                    {
                      for(string id : Ids)
                      {
                        // calling a static method sending id as paramter.
                      }
                    }
 
  }

In for loop for every id calling an static method with id as parameter.

The call static method will created an instance of another class which has nearly 10 queries and an http request.

am getting Too many SOQL queries: 201

This is my static method

global  class SClass
{
  
  public static void SMethod(String id)
  {      
                         
       
         Sclass2 s = new sclass2 (Id,false);
         s.test();// this method has http request and upto 10 soql queries
   }           
        
}

why do i get this even when we have created new instance for every id.

Any solution please.

Thanks,

1 Answer 1

0

Finish method runs don't have the asynchronous limits as the execute methods. Why don't you try and run your finish method logic in a different batch apex. You can call the batch apex from Queueable or in the finish method.

15
  • Am doing an callout in finish method. Since am doing an insert (dml), call out is not allowe after dml (correct me if am wrong) @mukul mahawariya Jan 17, 2023 at 11:46
  • Thanks brining that into my attention, I have updated the answer. Jan 17, 2023 at 12:04
  • So need to create another batch class with list of ids( 1000 and more ids) which will execute the below. in for loop in execute method.` Sclass2 s = new sclass2 (Id,false); s.test();// this method has http request and upto 10 soql queries ` does the batch class execute will not have the governor limitations ? Jan 18, 2023 at 10:57
  • So need to create another batch class with list of ids( 1000 and more ids) which will execute the below. in for loop in execute method. ` Sclass2 s = new sclass2 (Id,false); s.test();// this method has http request and upto 10 soql queries` does the batch class execute will not have the governor limitations ? Jan 18, 2023 at 11:31
  • Start, execute, and finish methods can implement up to 100 callouts each. You only need to iterate over the in a chunk of 100. SOQL limit is 200 in asynchronous apex. Jan 18, 2023 at 12:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .