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

Batch Apex - Two Queries
Hi all, I have the following code:
How can I make the accountList work inside the context of the batch? I would like to compare both lists for a match. Any other optimizations and improvements would be appreciated.
global class ProcessLinkBetweenWorlds implements Database.Batchable<sObject>, Database.Stateful { global List<Account> accountList = new List<Account>(); global Database.QueryLocator start(Database.BatchableContext bc) { accountList = [Select PersonContactId, concat_ID__c, PersonEmail, Name FROM Account WHERE PersonEmail != NULL AND FirstName != NULL AND IsPersonAccount = TRUE AND PersonMailingCountry != 'United Kingdom' AND Is_Master_Record__c = True]; // THIS QUERY IS TOO LARGE Set<String> accountConcatIds = new Set<String>(); for(Account a: accountList) { accountConcatIds.add(a.Concat_ID__c); } return Database.getQueryLocator( 'SELECT ContactId, SuppliedEmail, concat_ID__c From Case ' + 'WHERE ContactId = NULL AND SuppliedEmail = NULL AND Concat_ID__c IN : accountConcatIds' ); } global void execute(Database.BatchableContext bc, List<Case> scope){ System.Debug(accountList.Size() + '|' + scope.Size()); for(Case c : scope) { for(Account a : accountList ) { if(a.Concat_Id__c == c.Concat_ID__c) { // Match Found! } } } } global void finish(Database.BatchableContext bc){ } }
How can I make the accountList work inside the context of the batch? I would like to compare both lists for a match. Any other optimizations and improvements would be appreciated.
Call the class and assigne a List<Case> Variable.
Now loop through case and account in execute method.