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
dJadhavdJadhav 

Processing on batch result.

Hi,

 

I have two batch jobs.Each job has 1 callout. I want to do some processing after competion of both batch job.

 

Can any one help me  how to do this?

 

Thanks in advance.

 

Regards,

Dipak

Jia HuJia Hu
Have you tried finish method?
The finish method is called after all batches are processed. Use this method to send confirmation emails or execute post-processing operations.

doc is here,
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch_interface.htm
dJadhavdJadhav

Thanks for reply.

 

I kbow about finish() method. I don't want to process the result of indivisual batch job. I want to get the data from each thread and the do the processing. How to check both thread has completed and and then process.

 

public class Sync {
public void performSync(){

 	Batch1 batch1 = new Batch1();
    Id batch1Id=Database.executeBatch(batch1);
	
    Batch1 batch2 = new Batch2();
    Id batch2Id=Database.executeBatch(batch2);    
	
	 //Code to be executed after competion of both batch job.
   
}

 

Regards,

Dipak

vishal@forcevishal@force
Have a boolean variable in each process which would return true only once it reaches the finish method. That way, you would know if the batch has finished executing.
dJadhavdJadhav

Hi Vishal,

 

Thanks for replay.

 

I have added the boolean varaible in Both batch classes and intialized it to false. In finish method i have set that varibale to true;

 

public class Sync {
public void performSync(){
Batch1 batch1 = new Batch1();
Id batch1Id=Database.executeBatch(batch1);

Batch2 batch2 = new Batch2();
Id batch2Id=Database.executeBatch(batch2); 

// check whether both job are completed or not 
boolean isCompleted = false;
do{
isCompleted= batch1.getIsCompleted() && batch2.getIsCompleted();
}while(!isCompleted);
}
}

 

I am getting the error  "Too many script statemenet." Could you please tell what is wrong?

 

Regards,

Dipak

 

 

 

 

vishal@forcevishal@force
Happens with 'while' loop if not written properly. Now, as long as that variable isn't true, your code will keep on calling the batch method and being asynchronous, this will keep on calling that method. You'll need to modify your logic and think of another way to call the second batch.