jamessimone / apex-rollup

Fast, configurable, elastically scaling custom rollup solution. Apex Invocable action, one-liner Apex trigger/CMDT-driven logic, and scheduled Apex-ready.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RollupAsyncProcessor is creating a second queueable job per apex invocation

baobao917 opened this issue · comments

Hi @jamessimone ,

We are experiencing an issue where two different apex classes are trying to create queueable jobs.

  • RollupAsyncProcessor (ApexRollup apex class)
  • BT_TransactionService.createJournalEntry (custom apex class)

Our understanding is that during any individual apex invocation, Salesforce will only allow one queueable job to be added per apex invocation. Therefore we're getting thie error "Too many queuable jobs added to the queue: 2"
image

We're not sure how to handle this b/c we don't understand what the RollupAsyncProcessor class is doing. I'm not sure why it's firing at all b/c the objects being affected aren't any which we currently have rollups configured for. Any suggestions/insight you have would be appreciated.

I have added the debug logs which show the two classes being called. To make it a bit clearer, I have also added a second attachment which shows the two portions where those classes are called.

@baobao917 Based off of the S1 debug log.txt file, I can see lines like this: FLOW_START_INTERVIEW_BEGIN|65532f2f0cf49dcbc13b5adf61d718cac549c47-4e1c|Work Order - AS - CU - Trigger Apex Rollup which would seem to indicate that records associated with rollups are in fact being updated. By default, Apex Rollup uses Queueables - however, you can also have it use Batch classes or even synchronous executions by modifying the Rollup Control record (either the Org Default, or a control record specifically for these rollups) by changing the Should Run As picklist value.

Thanks @jamessimone . I temporarily deactivated the rollup which impacted the work order object and that temporarily solved our issue. It's curious b/c the process that we kicked off shouldn't have touched the work order object so I'm going to have to dig into our other custom class and see why it seems to be firing your RollupAsyncProcessor class.

Quick question on the rollup control should run as "batchable". How does this work exactly? I'm familiar with running it synchronously and as queueable but not as batchable. I know for sure that running it synchronously will not work for us for this particular rollup since we have so many automations on the work order object which is one reason why ApexRollups option to use queueable was a great fit

There isn't a lot of information in the rollup control section on batchable.
image

Thanks!

In this case, Batchable should do the same thing as starting up a Queueable - it's a bit slower to perform the entire operation, but that shouldn't really matter here.

Thanks @jamessimone. I tested and ran the rollup using a Rollup Control where Should Run As = Batchable. The grandparent rollup and the reparenting all seemed to function correctly.
image

image

One quick question....I observed that in the Apex Jobs, it still appeared to run as 'Queueable'. Is that correct?
image

Yes, that's correct. It's a bit of a hack, but it only starts as a batch in order to get going properly.

I will revamp the documentation about this - you've hit upon a weakness in the framework, and with Queueables in general; namely, that it can detect when it will be a problem to start up as a Queueable when all of your code has finished running, but if other code after Apex Rollup blindly fires off a Queueable, that can be an issue.

Ok thanks @jamessimone ! Should I go ahead and close this comment or do you want me to leave it open for you to close once you revamp your documentation?

You can leave it open - I'll close this after updating the README. Thanks!