3

I have object A that has the roll up summary field that sums the total price fields for records in object B. I have a field on Object B for sales tax that calculates based on the roll up summary in object A. The sales tax field is updated by process builder when a new record is added to object B. The problem is that the formula in process builder is calculating from the original value of the roll up summary field and not the new value. Example: two records have a total price of 10 and 20. The total in the roll up field is 30, I add another record that has a sales price of 10, when the sales tax field is updated it is calculated based on 30 (the original total) and not 40.

What would be a formula for process builder that would calculate the total including the new value?

  • Am I understanding correctly that your model is this: Object A has the rollup summary ("Total") of Object B's Amount field. Object B has the Sales Tax field, which is calculated based on the parent Object A's Total. Sales Tax is updated by Process Builder running on Object B, not Object A. Is that right? – David Reed Aug 24 '18 at 14:11
  • Yes that is the model. – DGOU182 Aug 24 '18 at 14:13
  • 3
    Why not calculate the sales tax in a formula field on the parent object and use another formula field to bring that value down to the child object? – gNerb Aug 24 '18 at 14:14
  • The sales tax on object B is a line item on that object. So the at the end there are line items for product x, y, z, etc. and another for tax. The formula worked to calculate on the parent worked, but the process still returns the outdated value for the line item on object B for tax. I changed what will be used to update the tax field with a field reference to the tax field on object A. – DGOU182 Aug 24 '18 at 14:32
4

I think you just need a different Process.

Going to the Order of Execution, it looks like what happens is this:

You have an Object A with Total = 30, deriving from two Object Bs with Amounts of 10 and 20.

You insert a new Object B with Amount of 10.

We enter the save process. Salesforce executes all of the triggers and so on down to step 13,

Executes processes and flows launched via processes and flow trigger workflow actions.

Your process goes off. It pulls the Total field from Object A, calculates the sales tax, and updates Object B. But here's the kicker - as you observe, it's looking at the "old" value of that roll-up summary Total, because roll-up summaries don't get updated by the system until Step 16:

If the record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the parent record. Parent record goes through save procedure.

So your Object B process is never going to see the change to the roll-up summary on Object A. I would not recommend using a formula in this process to try to "correct" for the changes in the current transaction; that will be impossible to get right in the fully general case.

Instead, I'd do one of two things: either, as gNerb suggests, put the Sales Tax field on Object A, where it naively makes more sense, and cascade it down to Object B via a formula field; or move the updater Process to run on changes to Object A. If you take the latter road, the Process will fire upon the update made by Salesforce to the roll-up summary field in Step 16 above, and you can then perform that update down to the associated Object Bs.

  • Do roll-up summary updates fire triggers/PBs? I know formula updates do not. – gNerb Aug 24 '18 at 14:21
  • 4
    Yes, rollup summaries do fire DML/trigger/PB. – David Reed Aug 24 '18 at 14:23
  • Good to know :P – gNerb Aug 24 '18 at 14:23
  • I think your solution is the right one, though. This data model is making DGOU182's life unnecessarily difficult. – David Reed Aug 24 '18 at 14:24
  • 3
    I don't think my solution is the right one. Sales tax is notoriously difficult to calculate as it changes place to place and very frequently. SF is also not a great platform for accurate billing services. The right solution is to integrate a third party tool like intacct, although, this path is much more expensive. – gNerb Aug 24 '18 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.