1

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.

2

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.

  • Thanks @sfdcfox for detail explanation, yeah logic inside execute method is fairly complex which might be taking more execution time, I can't go with 2000 batch size as I am making a callout from batch apex but I'll have to try different scenario to identify suitable batch size for my use case. My client was asking me is there a way to increase execution speed apart from optimizing code, like raising case to Salesforce etc but now I am clear about the issue. – Nachiket Deshpande Nov 16 '17 at 11:01
  • 1
    Certainly. You should set it as large as possible to still function for best performance. In theory, this could be 100, but it might be less depending on the size of each request. – sfdcfox Nov 16 '17 at 11:05
  • And no, you can't open a case with Support and expect them to fix it. Slow-running programs require optimizing code. – sfdcfox Nov 16 '17 at 11:05
  • Yeah, Thank you so much for your help @sfdcfox, answer accepted. – Nachiket Deshpande Nov 16 '17 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.