You need to sign in to do that
Don't have an account?
Air Foxx
Selecting two most recent child records from master
Still a newbie here. I'm trying to determine the best way to find the average unit cost of the two most recent invoices associated with each of multiple projects. The project names (which includes duplicates) are part of the master object and the relevant invoice fields (quantity and amount) are part of the child object. So far, this is what I have:
List<MasterObj__c> master = [SELECT id, (SELECT Invoice_Number__c, Inv_Amount__c, Inv_Quantity__c FROM ChildObj__r WHERE ORDER BY Invoice_Number__c DESC LIMIT 2) FROM MasterObj__c];
I need to find a way to assign the sum of invoice amounts and quantities for each project to a variables to calculate the average.
Any help would be appreciated.
Thanks!
List<MasterObj__c> master = [SELECT id, (SELECT Invoice_Number__c, Inv_Amount__c, Inv_Quantity__c FROM ChildObj__r WHERE ORDER BY Invoice_Number__c DESC LIMIT 2) FROM MasterObj__c];
I need to find a way to assign the sum of invoice amounts and quantities for each project to a variables to calculate the average.
Any help would be appreciated.
Thanks!
Average , Sum , ara maintianed in Maps against master record Id you can use them for your purose
Also, to assign the sum, quantity, and average to fields for reporting, I assume I would have to use the get (key) - e.g., double field = MastertoChildSum.get(m.id)?