You need to sign in to do that
Don't have an account?
vaishali sharma
Calling execute inside finish method of batch apex.
hi , i want to call excute method inside finish method of batch class . How can i achieve this . When i try to do this it throws error
/* Error: Compile Error: expecting a right parentheses, found 'BC' at line 100 column 58 */
Global void finish(Database.BatchableContext BC){
system.debug('finish method has beenn executed');
if (flag == false)
{
BatchDuplicateRecord batchDupreco = new BatchDuplicateRecord();
batchDupreco.execute(Database.BatchableContext BC,List<sObject> scope);
Database.executeBatch(batchDupreco,1000);
}
else
{
system.debug('your batch has succesfully executed');
}
}
/* Error: Compile Error: expecting a right parentheses, found 'BC' at line 100 column 58 */
Global void finish(Database.BatchableContext BC){
system.debug('finish method has beenn executed');
if (flag == false)
{
BatchDuplicateRecord batchDupreco = new BatchDuplicateRecord();
batchDupreco.execute(Database.BatchableContext BC,List<sObject> scope);
Database.executeBatch(batchDupreco,1000);
}
else
{
system.debug('your batch has succesfully executed');
}
}
Hi Vaishali,
I belive below line is not required for your requirement.
Thanks,
Prem Anandh
You don't need to call the execute method explicitly from the finish method of the batch apex. All you need to do is to call Database.executeBach() method from finish method.
it is good practice to check how many batch are executing in same time, as we cant execute more than 5 jobs in same time we need to check the number of jobs executing and then start another job.
So, I have queries AsyncApexJob object to check how many batch jobs are Queued,Processing,Preparing. if count is more than 4 then i am scheduling this batch to excute after 2 minue and in meanwhile other jobs will complete. if there are less than 5 jobs are processing in system then excute the batch now.
if you want to call execute method inside finish method, you need to pass batchablecontext value and list of record to execute. but in your current code you are not passing any value to it.
check below code for it, if any exception occur then call execute method with current batch context and scope as the list of record to proceed. please do let me know if it helps you.
Thanks,
Debasis