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
Laxman1975Laxman1975 

Help needed with Apex batch

Hi All,

I would like to create roll up summary of few fields from Account on account itself using Account Hierarchy. 

Using below query I can get sum of booking upto 3 levels in account Hierarchy.

SELECT SUM(Booking__c) 
                               FROM   Account
                               WHERE (Id =:accountId) OR (ParentId =:accountId) OR (Parent.ParentId =:accountIds

We have 50K accounts and that need to be processed in Batch. 

If I will do this in Batch with size 200 records then how to breakup above query so that Summary will be calculated only for accounts which are hierarchical connected? 

Or is it that I need to process only one account record at a time.

Appreciate help on this or any other solution/work around for this. Thanks

Laxman