Skip to main content

We have Orders over 72000 and I configured Invoice scheduler to run daily but it keeps failing with error message "Apex CPU time limit exceeded".

 

When I reached out to salesforce support, they said, we have to partition these orders into different buckets using blng__InvoiceBatch__c picklist and run multiple invoices. That means, I have to partition Orders into 10 (or 15) batches and have 15 Invoice schedulers run every day.

 

I know that Invoice scheduler internally is implemented by Apex Batch and Apex Batch should handle easily 72000 records, unless there is a bug in that Apex batch that runs behind Invoice scheduler.

 

Problem with partitioning orders into different batches are as follows:

  1. Every new order that is created should have a batch assigned..we have to implement that.
  2. We should schedule multiple Invoice schedulers targeting different batches and we also have to make sure that these batches don't run in parallel(otherwise we could run into locking issues).

What I prefer is :

 

Fix the Apex batch behind Invoice scheduler so that it doesn't run into Apex CPU time limit errors. We don't care, if it takes too long.

 

Anyone ran into these issues? 

 

This makes us think that we are the first biggest company that is implementing Billing package and running into all sorts of these issues but we are not, we have close to 200 users.

8 条评论
  1. 2022年5月17日 01:26

    @Ramesh Ale No, I am not saying we cannot process 72,000 orders in a single apex job. What I am saying is: we cannot assume because an apex job can process 72,000 records, we can process 72,000 orders without running into any limit issues. The CPU limit is applied to each batch of records. If a batch of 200 records exceed asynchronous apex CPU limit of 60 seconds, the batch will run into Apex CPU Time Limit exceeded error. One way to avoid this is to tweak the batch size to a lower number.  You are right about running smaller batches will take longer for the job to complete and also will run into record locking issues. However, please read the guidelines for invoice run. Reducing the batch sizes will slow invoice run speeds but reduces the chance of errors from batches with many invoice lines

     

    If we reduce batch size, to mitigate the slow invoice run speeds, we can take advantage of running multiple invoice schedulers by carefully designing the approach. For example, you can setup once batch for accounts starting with letter A to M and another scheduler for accounts starting with letter N to Z. We need to have some automation on orders to update blng__InvoiceBatch__c, which is used in invoice scheduler to pick the orders matching with the batch.

     

    It will be helpful to have a full sandbox to experiment and tweak your approach. You also need to evaluate any other custom automations that are getting triggered causing the limit issue. All these contribute towards the 60 second CPU limit for a batch of records.  

0/9000