You need to sign in to do that
Don't have an account?
Luke Higgins 22
Add values from a parent-child SOQL query
I am trying to get the sum of a result from a parent-child query and insert the sum into a field on the parent. The object placement__c has a child record timesheet__c with the field, hours__c, for each week. I am trying to get the total of approved hours for the last 2 weeks on the placement__c record through a batch class. I can get the timesheet__c records grouped with this SOQL query of the placements__c, but I'm not sure how to get to the final product of adding them.
SELECT Id, Name, (SELECT jstcl__Total_Hours__c FROM jstcl__Timesheets__r WHERE jstcl__Week_Ending__c = LAST_N_DAYS:15 AND jstcl__Status__c = 'Approved') FROM ts2__Placement__c
Thanks for your response! The code you gave me is giving me trouble on inserting it in into a batchable class. I'm trying to set it up in the same way as another batch class I've written but it doesn't seem to comply with the outline. The totalPlacementHour needs to go in the Hours_Worked_the_Past_2_weeks__c field on the placement. Here's what I've been trying to do:
Do you have any idea how to help?
Thanks again!