jamessimone / apex-rollup

Fast, configurable, elastically scaling custom rollup solution. Apex Invocable action, one-liner Apex trigger/CMDT-driven logic, and scheduled Apex-ready.
MIT License
222 stars 30 forks source link

Unexpected Behavior with Rollup to Ultimate Parent #590

Open PhilTerz opened 6 months ago

PhilTerz commented 6 months ago

Rollup to Ultimate Parent is presenting several issues. I have tried to test scenarios to find a pattern but it is not always clear. In general, the counts don't seem correct. Specifically I have noticed and replicated these when using a distinct count with ultimate parent:

  1. Deleting rolling-up child record from the ultimate parent causes the count to decrease by 2x the regular parent's number of children.
  2. Adding a rolled-up child record to the ultimate parent causes the count to increase by 1 + 2(regular parent # of children).
  3. Deleting a rolled-up child record from the regular parent causes the count to decrease by the remaining number of children on the regular parent. (Regular parent had 14 children, I delete one, the regular parent now has 13 children and the UP's count decreases by 13).
  4. Adding a rolled-up child record to the regular parent causes the count to increase by the new number of children. (Regular parent had 13 children, I create one, the regular parent now has 14 children and the UP's count increases by 14).
  5. Also, using the Recalculate Rollups LWC button on the ultimate parent only counts the ultimate parent's children.

I am less certain of how Ultimate Parent should work so perhaps I am mistaken. Are children from the ultimate parent supposed to get counted? In the wiki article example:

In this example, it's possible using Apex Rollup to take information from Contacts A, B and C and roll them all up to Account A.

If Account A had children, is Rollup to Ultimate Parent intended to count Account A's children also with Account B and C's? If A had its own child Contact X, should an ultimate Parent rollup COUNT result in four? This was the assumption I was operating on.

jamessimone commented 6 months ago

@PhilTerz I will have a to take a look and get back to you. I appreciate you providing examples!