I'm working on a small project where a customer can be the master in a master-detail relationship to more than a single project object. Projects have a currency 'Max_Budget__c' and what I want to do is calculate the max budget per customer by adding the Max_Budget__c per project. This means that I need to collect a List per customer but also need customer stored so I can update the Max_budget__c object of it. I was thinking about storing it in a Map with Customer__c as key and List (of Currency__c) as value, But I'm not sure how to do this in a single SOQL Query or if i'm even looking in the right direction. Any ideas? Thanks in advance

1 Answer 1


You can add a roll-up summary field to your Customer__c object that contains the MAX (or SUM) of the related detail Project.Max_Budget__c fields. The platform will maintain that value for you. This works on currency fields.

By having it in your data model, you can display it on the screen or query it to reference it in your logic e.g.;

Customer__c[] customers = [
        select Name, Max_Budget_Rollup__c
        from Customer__c
        order by Max_Budget_Rollup__c desc
  • but what if I can't reference the value I want to sum, because the budget of a project is calculated using an employee salary which is an outside object (apparently I can only reference formula's that are calculated using 'local' values) Oct 7, 2014 at 8:56
  • 3
    @DeHeerJørvanOerle In that case if you want to stay declarative you can use a workflow field update to copy the value of your formula field (or replace it entirely) into a non-formula field, which you can then roll-up. Oct 7, 2014 at 9:23
  • @AlexTennant blugh it seems wrong to make such a arbitrary work-around. But it works ^^ Oct 7, 2014 at 9:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .