+ Start a Discussion
balaji Jayararmanbalaji Jayararman 

I have developed a batch class which process around 5000 record. when i set the batch size to 1, the batch run succesfully. But if i set the batch size to 2, i got Apex Cpu time limit exception. can anyone help to fix this issue?

Sohan Raj GuptaSohan Raj Gupta
Hi Balaji,

Can you share your code, so I can check.

Sohan Raj Gupta
Agree with Sohan here: please share a code as we can take a look at it.

However, keep in mind that if you are writing a test classes and your test requires multiple iteration of EXECUTE method then it may throw an error since in test classes, it won't allow more than one iteration of an execute method.

Here is a more detail explanation: https://success.salesforce.com/answers?id=9063A000000e6MZQAY

Tip: if you are trying to maximize Batch size - do 2000 instead. In your test classes write something along these lines,
Database.executeBatch(New MyBatchName(), 2000);

This will make your Batch Apex's execute method to run once for bulk of 2000 records. 

Hope this helps and if it solves the puzzle then please mark it solved!