1

For example, I want to have a rollup summary field called 'Gross Total' on the Invoice object like this:

Rollup (SUM(InvoiceLineItems (Record Type: Original)__r.ListPrice))

However on the Invoice line item (Record Type: Original), my ListPrice custom field formula is like this :

Formula (IF (Is_Makeup_Charge__c == False, 
Enrollment__r.Course__r.List_Price__c, 
Total_Makeup_Amounts__c)

I just found out not long ago that roll up summary fields cannot roll up formula fields referencing other objects.

So I was thinking to write a trigger for this instead Invoice__c.GrossTotal__c but realised triggers referencing formulas won't really work too? Which means I probably need a trigger to calculate the formula for the list price too?

Need Advise.

1 Answer 1

2

A trigger could work with a cross-object formula field just fine. There is a purely declarative workaround though.

By using a workflow field update (and with the workflow rule set up so that it runs every time the record is edited) to copy the value of your formula field into a new field, you basically make that value live on the object you're trying to summarize.

The field that you copy into will be available for rollup summaries.

The downsides to this approach are:

  • workflow field update means your update triggers will be run a second time each time you update the record
    • That means that you need to be more vigilant with query usage
    • Also makes incremental updates harder (e.g. total = total + new tends to be double-applied in these scenarios)
  • A change to the cross-object value (i.e. Enrollment__r.Course__r.List_Price__c) alone does not mean your rollups will update
2
  • That last downside you mentioned sounds really bad. I rather use triggers then.
    – compski
    Jun 21, 2020 at 15:28
  • 1
    @compski A trigger won't change the last bullet. A simple fix, though, is to include a Process Builder to update the child records, which in turn would update the declarative workflow field update, which would then recursively rollup to the other object. You can do this all with no code.
    – sfdcfox
    Jun 21, 2020 at 15:33

You must log in to answer this question.

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