function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Narayana Reddy 30Narayana Reddy 30 

How to delay specific batch job execution

Hi,
I have a scheduler class which reads list of objects (object1, object2, object3) and invokes batch class for each object.
Batchclass bc = new Batchclass(object1)
batchJobId= database.executeBatch(bc,1000);

I would like to delay the batch job execution if object is 'Contact' . CAn you please share how it needs to be done ?
Vineela ProddaturuVineela Proddaturu
Hi Narayana Reddy, 
Please, try like this. It will delay 5 seconds, and  If you want to delay 10 sec, you should add 10 seconds in while loop.

batchclass bc = new batchclass();
Id batchJobId = database.executeBatch(bc,1000);
datetime start = system.now();
while(system.now() < start.addseconds(5)){}
System.debug('wait start time :'+ start);
System.debug('Wait end time :'+ start.addseconds(5));

If, it helps you. pls, mark it as a best answer.
SwethaSwetha (Salesforce Developers) 
HI Narayana,
I see you also posted on https://salesforce.stackexchange.com/questions/389000/how-to-delay-specific-batch-job-execution. Please share your usecase.

Related: https://salesforce.stackexchange.com/questions/302790/add-a-delay-timer-when-a-batch-class-is-executed-without-scheduler

Thanks
Narayana Reddy 30Narayana Reddy 30
Issue is we are updating opportunities and quotes via batch jobs and getting not able to acquire lock error. So wanted to delay quote records update by few mins to avoid the account lock error. FYI- we don't want to do any major changes and hence checking on delay approach to eliminate the issue temporarily