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
Andrew LaBaireAndrew LaBaire 

How to update parent account with all child accounts data using apex class?

Apoligies I'm still rather new and learning. My problem is I have a list of parent account with the field Funded_Deals__c and I need to find all child accounts related to their respective parent accounts, then do the sum of that field for all child accounts related to the parent account and update the parent account with that sum. I feel like the way to do this would be to have 2 lists one for parent and one for child accounts and then map the data but I need a little help figuring out exactly how to do it. 
Lexi KansLexi Kans
To update a parent account with data from its child accounts using an Apex class in Salesforce, you'll need to create a custom Apex class that orchestrates the process. First, ensure that there's a proper parent-child relationship established between your account records. Then, develop the Apex class with methods that retrieve child account data using SOQL queries, perform data aggregation based on your requirements, and finally update the parent account with the aggregated information using DML operations of virtual assistant (https://weareworking.com/). Start by querying the relevant child account records associated with the parent account using SOQL. Apply filters and conditions as needed to fetch the specific data you're interested in. Next, iterate through the queried child accounts and perform the necessary data aggregation, which could involve calculations such as sums, averages, or counts, depending on your use case.