You need to sign in to do that
Don't have an account?
Dbjensen
How to Pass Set and Map to Batch Apex class
I have created a batch class. In the Finish method, I am calling another batch class. Can I pass both a set and map to the second batch class?
This is the first batch class.
Below is the AddAgentToLeadBatchJob class which I am passing in the set 'customerPhone' from the above class. How can I pass in the map 'agentName' in addition to the set? (If I create a second constructor, I get an error.)
This is the first batch class.
- public class AddLeadToCallBatchJob implements Database.Batchable<sObject>, Database.Stateful{
- Set<String> customerPhone = new Set<String>();
- Map<Id, String> agentName = new Map<Id, String>();
- //this is the finish method which I'm passing in customerPhone
- public void Finish(Database.BatchableContext bc){
- Database.executeBatch(new AddAgentToLeadBatchJob(customerPhone), 100);
- }
Below is the AddAgentToLeadBatchJob class which I am passing in the set 'customerPhone' from the above class. How can I pass in the map 'agentName' in addition to the set? (If I create a second constructor, I get an error.)
- public class AddAgentToLeadBatchJob implements Database.Batchable<sObject>, Database.Stateful{
- Map<Id, String> agentName = new Map<Id, String>();
- Set<String> customerPhone = new Set<String>();
- //constructor
- public AddAgentToLeadBatchJob(Set<String> customerPhone){
- this.customerPhone = customerPhone;
- }
You can try to modify the constructor of AddAgentToLeadBatchJob to take both a Set<String> and a Map<Id, String> as parameters, like this:
Then, in the Finish method of AddLeadToCallBatchJob, you can create a new instance of AddAgentToLeadBatchJob with both the customerPhone set and the agentName map as arguments, like this:
If this information helps, please mark the answer as best. Thank you
All Answers
You can try to modify the constructor of AddAgentToLeadBatchJob to take both a Set<String> and a Map<Id, String> as parameters, like this:
Then, in the Finish method of AddLeadToCallBatchJob, you can create a new instance of AddAgentToLeadBatchJob with both the customerPhone set and the agentName map as arguments, like this:
If this information helps, please mark the answer as best. Thank you