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
210 stars 30 forks source link

Apex CPU time limit exceeded when a batch is run #539

Closed baobao917 closed 9 months ago

baobao917 commented 9 months ago

I've created this issue b/c it is occurring more frequently now. Anytime I have to run an update on a batch of records of the rollup's child object, ApexRollup gets an Apex CPU time limit exceeded error. It occurs if it occurs in a scheduled flow or if I do a batch update of records directly. In my experience, I'm getting the error pretty consistently on any batches exceeding 70 (whereby the update operation isn't doing anything complicated...just populating a field value).

Discussed in https://github.com/jamessimone/apex-rollup/discussions/519

Originally posted by **baobao917** October 8, 2023 I have a simple scheduled flow that runs that updates a collection of records. It is a very simple flow just updates one field on each of the records in the collection. It has previously worked without any issue. These records are the child object in an Apex Rollup. Now that I've introduced the flow trigger on the child object, it has pushed the transaction time beyond the APEX CPU limit. I've tried to create the apex rollup flow trigger as asynchronous but it appears that it is not possible. Do you have any suggestions?
jamessimone commented 9 months ago

@baobao917 I've managed to reproduce this issue this morning. I have some ideas on how to streamline the process to make these updates from Flows more performant.

jamessimone commented 9 months ago

@baobao917 I'm nearly finished with the current round of optimizations, many of which I've pre-deployed to your sandbox. Hopefully I'll be able to wrap up this version today or tomorrow.

baobao917 commented 9 months ago

Thanks @jamessimone ! I saw v1.6.5 was related to this. Do you have an idea of what the batch size improvement should be now? The full 200? I saw that you noted that this was the low hanging fruit and that possible future enhancements possibly are coming as well....looking forward to it!

jamessimone commented 9 months ago

@baobao917 You can check out the Test - Apex Rollup Bulk Update James flow I made in your sandbox - that test was with ~100 records. I can expand the date range that flow is using to ensure higher record counts continue to work.