apex-rollup
apex-rollup copied to clipboard
Incorrect rollup calculations when child records are inserted in separate transactions at the same time
Recreate issue: Bulk Insert child records with a smaller batch size(let's say 1) and use multiple threads, the rollup calculations get messed up. This is because the parent record update is performed in an Async Queueable context unlike the parent record being locked for sometime in native salesforce roll-ups. Eventually, each thread tries to update the parent record rollup field parallelly but does not wait for either. E.g. Initial Count() - 0 Try inserting 2 records parallelly, then both try to update Count to 1 instead of 1+1 = 2.
Use Case: We have integrations that are pushing records in smaller chunks in separate transactions.