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
Megha Mittal 19Megha Mittal 19 

What is the way the batches are divided in a nested child relationship query

I want to know how the batches will be divided in a relationship query from querylocator.
So if I have a batch size of 50, will it send to the execute method in batches of 50 for parent object + the child objects for these 50 parents
Or 
It will be a total of 50 from both queries.
Best Answer chosen by Megha Mittal 19
RakeshRakesh (Salesforce Developers) 
Until it exceeds the default batch size 200, it will process. In your case, it will process both objects records (50 records from account object + child records of this 50 accounts).

All Answers

RakeshRakesh (Salesforce Developers) 
Hi Megha,

The minimum size for Batch Apex is 1.
The maximum size for Batch Apex is 2000.
The default is 200. 
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. 
  • An execute method is called depends on the batch size and number of records. Assume that you have 1000 records, then execute method called 2 times. 
  • Finish method called only once after the execute finished.
  • To know more about Batch Apex, please refer the Batch Apex Developer Guide https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch.htm

Hope this helps you!
Please mark it as solved, If this reply was helpful.

Thanks,
Rakesh
Megha Mittal 19Megha Mittal 19
Hi Rakesh,

I am aware of this information. I wanted to know how will the batch size work when the query is relationship like 
database.getquerylocator(select id,name ,(select name,id from contacts) from account)

Considering I have set the batch size as 50
In this how will the batch size work,
Will it be like 50 records from account object + child records of this 50 accounts
or 
50 records from account + contact combined.

Thanks.
RakeshRakesh (Salesforce Developers) 
Until it exceeds the default batch size 200, it will process. In your case, it will process both objects records (50 records from account object + child records of this 50 accounts).
This was selected as the best answer