+ Start a Discussion
Sandesh D GanjareSandesh D Ganjare 

How to insert delay in apex class?

I am new to salesforce. I have an apex class from where I am calling a web service. I want to insert the delay of 10 sec so that I can handle the 'over query limit' error. 
thanks in advance!
Chandra Sekhar CH N VChandra Sekhar CH N V
In Apex there is no function to delay the code execution. If its a batch apex, Use optional param of the method that kicks off the batch. Database.executeBatch(new MyBatchClass(), 10); will walk through "whatever comes from query locator" in chunks of 10 records at a time.

Check if future annotation can be added for your scenario - 
Stuart FlemingStuart Fleming
This might work, but you might get other errors

public static void sleep(Integer secs ) {
datetime myStartDateTime = datetime.now();
DateTime newDateTime = myStartDateTime.addSeconds(secs);
while (datetime.now() < newDateTime ) {
// sleeping here...sort of
datetime myEndDateTime = datetime.now();
System.debug('start:  ' + myStartDateTime ) ;
System.debug('end:  ' + myEndDateTime) ;