You need to sign in to do that
Don't have an account?
Srikant Swain 8
Batch Class to calculate percentage on child records amount field and populate it on a custom object
I need to write a batch class monthly that will query all child records and calculates the percentage consumed from an amount field and creates a new record in a 3rd Object.
Example:- Object "Program" has multiple children "projects"(can have more than 200) with lookup relation and has a field "Amount". The parent "Program" object has a field "Allocated Total Amount". I have to query all children and calculate the sum of the amount and take percentages like (Sum of Amount/ Allocated Total Amount * 100). After that, I have to create a record in another object "Summary Table" with Program Name, Start Date, and End Date from the Program Object and calculated the Percentage in a field.
Example:- Object "Program" has multiple children "projects"(can have more than 200) with lookup relation and has a field "Amount". The parent "Program" object has a field "Allocated Total Amount". I have to query all children and calculate the sum of the amount and take percentages like (Sum of Amount/ Allocated Total Amount * 100). After that, I have to create a record in another object "Summary Table" with Program Name, Start Date, and End Date from the Program Object and calculated the Percentage in a field.
I believe you can take the below approach.
You can have a stateful variable to calculate the required amount, by implementing Database.Stateful in the batch class.
In the Finish method of the batch, the insertion to the 3rd object can be done by taking the amount value from the stateful variable.
Thanks.
All Answers
I believe you can take the below approach.
You can have a stateful variable to calculate the required amount, by implementing Database.Stateful in the batch class.
In the Finish method of the batch, the insertion to the 3rd object can be done by taking the amount value from the stateful variable.
Thanks.