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
krishna casukhela 7krishna casukhela 7 

batch size in batch apex

Hello friends
I have a doubt in batch apex.
I know by default batch size =200.
a)can we change the batch size? if yes where do we change it. assume I want to make it 400
b) if I have to process 1Lakh records for a particular object using Batch apex, how many times will the methods (START , EXECUTE , FINISH)
    be called?

Thanks
Krishna​​
​​​
Best Answer chosen by krishna casukhela 7
Arunkumar RArunkumar R
Hi Krishna,

     The default batch size is 200 and the maximum batch size is 2000. 

              Database.executeBatch(new RunThisBatch(), 500);

You can set batch size like above. 500 is the batch size in the above syntax. 

Start method is called only once. 
Excute method is called depends on the batch size and number of records. Let say, 1000 records, then excute method called 2 times. 
Finish method called only once, after the excute finished.

All Answers

Arunkumar RArunkumar R
Hi Krishna,

     The default batch size is 200 and the maximum batch size is 2000. 

              Database.executeBatch(new RunThisBatch(), 500);

You can set batch size like above. 500 is the batch size in the above syntax. 

Start method is called only once. 
Excute method is called depends on the batch size and number of records. Let say, 1000 records, then excute method called 2 times. 
Finish method called only once, after the excute finished.
This was selected as the best answer
Vishwanath H RVishwanath H R
Hi Arun,
This may be late comment on this topic. But if you can answer I have one question. How the batch class decides the batch of records to be processed i.e.,how it identifies first  500records for processing and after processing 1st batch how it gets records for next batch..!? Is it decided in start method or execute method ?
Ajvad AjuAjvad Aju
Hi Vishwanath,

If the batch size is 500, then 500 records will move to execute method from start in the first batch. Since its a descrete transaction process.