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
Anudeep BAnudeep B 

Need Batch apex clarification on my queries.

I messedup with different answers of batch apex help me on this.


Please correct me below if i go wrong any where.!

/* All in case of batch apex*/
* querylocator ---- will fetch 50 million records.
* one soql query -- will fetch 50000 records.
* getquerylocator-- will fetch 10000 records.
===========================================

Please give me clarification for below.

* How many SOQL queries we can write in a single Batc Apex Class.?
* If we can use more than one SOQLs, can we write on different Objects in the same Batch Apex class.?
* Can SOQL query write in all the methods.(start(), execute(), finish()).?

 Give me clarification on this points, i am confused on these things, even shortly or with explanation.

Thanks.
AshwaniAshwani
* How many SOQL queries we can write in a single Batc Apex Class.?
You can wirte 100 SOQL queries in single batch chunk (execute method of Batch). 

* If we can use more than one SOQLs, can we write on different Objects in the same Batch Apex class.?
In execute method there is no restriv=ction ob object referenced in different queries. But all queries must no return records more than 50000

* Can SOQL query write in all the methods.(start(), execute(), finish()).?
In start() method batch query is written only. It can only be one object at a time. Chunks [execute()] of batch decided by start() method. In execute() and finish() you can write as many queries come under apex governor limit. 
Anudeep BAnudeep B
here is a task.

i have 70000 records in an object, i want to do batch apex. so a single SOQL query will retirve 50000 records, how to get remaining 20000 records in a same batch apex class..?
Suneel#8Suneel#8
You can use Database.QueryLocator to process more than 50,000 records in Batch as below.It works!!
global Database.QueryLocator start(Database.BatchableContext bc){   
             return Database.getQueryLocator([Select Id from Account ]);
}

 
Anudeep BAnudeep B
//Object having 700​00 records.


global class Accupdt implements database.batchable<sobject>
{
   global database.querylocator start(Database.BatchableContext bc)
   {
    string status = 'select id from account';   //This SOQL will get 50000 records.
    return Database.getQuerylocator(status);    //This will get 10000 records.
    }                                         //explain how its process of processing between 50000 and 10000.

   global void execute(Database.BatchableContext bc, list<account> scope)
   {
   list<account> ac = (list<account>)scope;
    for(account c:scope)                  // i given scope is 2000 per batch. in database.executebatch(bc,2000)
     {
      c.phone = 9999999;
     }
    update (ac);

   global void finish(Database.BatchableContext bc){}

}


//executing.......
/*btchacclis BC = new btchacclis();
Database.executeBatch(BC,2000);*/


/*According to my Batch Apex class it would process 25 transactions(taking 50000 records).
all the limits are completed for batch apex. Now how my remaining 20000 records will get.
I am confused here.  */

//How the above program is processing...i have followed some explanation resource but not clarified.