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 

Certain group of records to execute in same chunk in Batch apex

Relation Ship
Account (Parent) - Opportunity (Child)
Account (Parent) - Alert (Child)

Question: Is it possible to make a group of records to be executed in same batch in Batch Apex?

Scenario:
10,000 Opportunities will load to the system with below informtion

AccID     OppName     OppDate  
XXXX        Op-x1          4-Mar-2022    
XXXX        Op-x2         4-Mar-2022
YYYY        Op-y1         4-Mar-2022
YYYY        Op-y2          4-Mar-2022


Requirement is, it should create an Alert for the group of same Account and Same OppDate data. 

From the above data it should create 2 Alerts as the data shows two different Accounts on same date.

The challenge here is I couldn't see any control on Batch class to send same set records in one same batch. Any workaround solution for this situation? 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Anudeep,

We cannot have any control on how the batch chunks runs as it is determined only while running the batch.

If possible try to write sort by accountid may be this will work for some extent I guess.

If this solution helps, Please mark it as best answer.

Thanks,