+ Start a Discussion
MattyDHLMattyDHL 

Trigger - Finding the Sum of a Map

I have a custom object that linked to account that contains revenue information.

 

The Custom Object can have many rows, and I need to find the Sum of one column for the all rows.

 

I have created a trigger that fires on the update of the custom object.

 

If I add the account ID and the revenue into a map, how can I add them all together?

 

Something Like?

 

Map<Id, Double> AccUpdate = new Map<Id, Double>();

 

Sum WHERE Account ID's are the same?


Thanks in Advance.

 

Matt

 

Best Answer chosen by Admin (Salesforce Developers) 
Anand@SAASAnand@SAAS

Is there a specific reason why you can't use "roll up summary field"?  You should think about using "Aggregate queries". Click here  for more information.

 

The construct your are trying to do is not possible using apex and SOQL. You either have to use aggregate queries or iterate through the records and sum them programatically.

All Answers

Anand@SAASAnand@SAAS

Is there a specific reason why you can't use "roll up summary field"?  You should think about using "Aggregate queries". Click here  for more information.

 

The construct your are trying to do is not possible using apex and SOQL. You either have to use aggregate queries or iterate through the records and sum them programatically.

This was selected as the best answer
MattyDHLMattyDHL

Thanks, didnt even think about the roll up field summary.

 

Matt