You need to sign in to do that
Don't have an account?

String Batch Job (string job not receiving all set items)
I have created a batch class. In the Finish method, I am calling another batch class. I am passing the phone numbers from the first class to the second class using a a set called 'customerPhone '. From what I'm seeing, the second class is not receiving the full list of phone numbers.
This is the first batch class.
//this set is populated from the execute method. I can see in the logs all phone numbers in the set.
Any help would be greatly appreciated.
Thanks,
This is the first batch class.
//this set is populated from the execute method. I can see in the logs all phone numbers in the set.
- Set<String> customerPhone = new Set<String>();
- //this is the finish method which I'm passing in customerPhone
- public void Finish(Database.BatchableContext bc){
- Database.executeBatch(new AddAgentToLeadBatchJob(customerPhone), 200);
- }
- Set<String> customerPhone = new Set<String>();
- //Query leads with matching phone numbers from tethr event
- public Database.QueryLocator start(Database.BatchableContext batchContext){
- return Database.getQueryLocator( [SELECT Home_Phone_Removed_Special_Characters__c, Email, Tethr_Agent__c FROM Lead WHERE Home_Phone_Removed_Special_Characters__c IN :customerPhone ORDER BY CreatedDate ASC]);
- }
- public void execute(Database.BatchableContext batchContext, List<Lead> eventQuery){
- System.debug('customerPhone in execute...' +customerPhone.size());
- }
Any help would be greatly appreciated.
Thanks,
You mentioned that you can see all phone numbers in the set in the logs, but it's important to confirm that the set is actually being populated correctly. You can add a System.debug statement in the execute method of the first batch class to check if the phone numbers are being added to the set as expected.
Check if there are any duplicates in the set of phone numbers. If there are duplicates, the second batch class may not receive all the phone numbers that were passed from the first batch class. You can use the size() method to check the size of the set after removing duplicates.
For Example : Check if the second batch class is processing all the records it receives. In the execute method of the second batch class, you can add a System.debug statement to check if all the records are being processed:
Hope the above information helps !
Thank you.
1. In the execute method, the customerPhone set is 200 (red X in pic below)
09:19:11.0 (23477330)|USER_DEBUG|[35]|DEBUG|size of customerPhone set... 200
2. Then the second batch runs.
3. In the finish method, the size of the customerPhone set is 99 (blue X in pic)
09:19:12.0 (12945304)|USER_DEBUG|[50]|DEBUG|size of customerPhone in finish statement... 99
4. This is the start method the second batch job which shows the # of records passed in from the first batch class: (red circle in pic)
09:19:12.0 (14221841)|USER_DEBUG|[25]|DEBUG|customerPhone in start...99
You'll notice there is no debug statement for the first 200 batch of records. The logs above the red circle are just updates to the second batch class of 99 records. Would it be helpful for you to see the entire code - it's fairly small?