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
Sid LightningSid Lightning 

Delete Opportunity when child object Grand total is 0?


I have a custom object as child to opportunity object. 

I want to delete opportuntity every night, when all the child records for it is 0.

I want to write a batch apex(schedulable), which deletes all such records at 12:00 in the night.

So lets say,

If an opportunity has 2 child records, and the Grand Total value on both child records is 0, I want to delete the opportunity along with its child record.

It should only happen, when both child records value is 0. In case where the child record value is there for one of the childs.. it shouldnt get deleted
is Grand Total is a custom field on child object ? and when in all child records this field value is 0, in that case parent opportunity should be deleted. Correct me if I am wrong.
Sid LightningSid Lightning
Yes.. The child name is "PI" . In cases where all PI's are 0. i want the opportunity to be deleted