+ Start a Discussion

A Rollup Challenge (or RollDown if you will)

I have an unusual requirement. From within a set of child records (I will use Invoices as an easy example) I need to find whether the current invoice record is larger or smaller than the previous largest invoice as of the date of that line item


This needs to show in each record the status as of the date of that record so it's not just a simple rollup of the MAX of all records. It also needs to dynamically update if prior invoices are deleted or updated as well. 


Think of this as a cascading value that will possibly be different with each record. I think of it as a "Roll Down" or "Roll Previous"  or a max of prior siblings. 


I am looking for a good way to implement this that doesn't max out governor limits. 


Any thoughts would be appreciated. 


Assuming that you have invoices, you can store the max value in a custom setting and query the same at all places. To update the custom setting record, use a aggregate query in a trigger.

Thanks for the thought, just to clarify...EACH RECORD has to look BACKWARDS in time to ONLY prior records (there is additional filter criteria as well) to calculate the MAX at that given date in time.

EACH record could see a totally different number since prior invoices could come/go/change.