[SalesForce] Schedule Job Processing is Very Slow

I have developed one Apex Batch Class, which holds logic to query data from multiple objects, insert/update records for multiple objects and there is one callout using which I am sending data from Salesforce to external system.

There are more than 2 Lakh of records in org and with batch size 5 its taking around 5-6 days for processing.

  1. I wanted to understand what affects the execution speed of scheduled jobs, scheduled jobs are getting scheduled at specified time ,but execution is getting delayed.

  2. Is there any way using which I can increase the execution speed for scheduled jobs, I can go with increasing batch size say 10 , but what I wanted to understand how a processing time for scheduled job is calculated.

Best Answer

I wanted to understand what affects the execution speed of scheduled jobs, scheduled jobs are getting scheduled at specified time ,but execution is getting delayed.

The system executes jobs based on resource availability. The actual execution time may differ from the scheduled time, although it is usually only off by a few seconds in most cases.

Is there any way using which I can increase the execution speed for scheduled jobs, I can go with increasing batch size say 10 , but what I wanted to understand how a processing time for scheduled job is calculated.

All Apex Code has only one speed: full speed. If your code is slow, it is most likely because of the logic in the execute method of your batchable class; this is the part that takes the most amount of time when processing data. You will need to optimize your execute method so that it runs faster.

This might mean using maps instead of putting loops inside of other loops, using more efficient hashCode/equals methods, optimizing encryption, etc. There's no way to give you specific advice without seeing your code.

If possible, you should set your batch size as large as possible. Processing 2,000 rows per batch is far more efficient than processing 5 records per batch. You should experiment to see how many records per batch would be appropriate for your use case.

Related Topic