I have the following code:
global class ProcessLinkBetweenWorlds implements Database.Batchable<sObject>, Database.Stateful {
global Integer recordsProcessed = 0;
global List<Match_Holder__c> matchList = new List<Match_Holder__c>();
global List<Case> caselist = ProcessLinkCases.listCase();
Set<String> caseConcat = new Set<String>();
global Database.QueryLocator start(Database.BatchableContext bc) {
for (Case c : caselist){
caseConcat.add(c.Concat_ID__c);
}
return Database.getQueryLocator(
'Select PersonContactId,concat_ID__c,PersonEmail, Name from Account ' +
'where PersonEmail != Null And IsPersonAccount = True And Is_Master_Record__c = True ORDER BY CreatedDate DESC '
);
}
global void execute(Database.BatchableContext bc, List<Account> scope){
for(Account a : scope) {
for(Case c : caseList ) {
if(c.Concat_Id__c == a.Concat_Id__c) {
Match_Holder__c match = new Match_Holder__c();
match.Name = 'Match!: ' + a.Id + ' | ' + c.Id;
matchList.add(match);
}
}
}
upsert matchList;
}
global void finish(Database.BatchableContext bc){
System.Debug('Match list size: ' + matchList.size());
}
}
I'm trying to optimize this Batch Apex class, it currently runs on 700,000+ records so any gain I can get would be beneficial.
I can't think of another way to check if the fields on the two objects match without the nested for loops for account scope and case list. Is there any way I can gain some speed and maybe get my goverenor limit usage reduced?