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
dev401hasdev401has 

Passing variable from batch Apex to another batch Apex?

Hi All,

 

I have a requirement where I need to serialize batch apex.

I came across this link in cookbook: http://developer.force.com/cookbook/recipe/serialize-batch-apex

 

This is a good example but I have a concern regarding passing parameters in the batch apex.

In the example the queries in Start method are simple with Limit 1000. I have to query with where condition of ID. I wil get ID value in first batch apex but while calling second batch apex i wont get that ID as it will become null. How can i pass the ID from one batch apex to another? or is there any other method where we can keep that ID as global and use in batch apex?

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Cory CowgillCory Cowgill

If your following that Cookbook example, you can pass the parameter in the Email.

 

Then, in your Email Handler Service, retrieve the information from the body or subject line of the email.

 

Then, when you instantiate your Batch Apex in the Email Handler class, you can pass along your information to the Batch Apex class.

All Answers

Cory CowgillCory Cowgill

If your following that Cookbook example, you can pass the parameter in the Email.

 

Then, in your Email Handler Service, retrieve the information from the body or subject line of the email.

 

Then, when you instantiate your Batch Apex in the Email Handler class, you can pass along your information to the Batch Apex class.

This was selected as the best answer
Ritesh AswaneyRitesh Aswaney

how about dumping the parameters to be passed into an object, or even a custom setting (saves you the soql), which is then stateful across batch invocations.

nagalakshminagalakshmi

Hi Cory,

 

Can you please provide the sample code to pass the variables from one batch another through Email Handler class to Email Handler Service. I am also seeking for the same thing. Please help me out.

 

Thanks,

Lakshmi.