I'm trying to update a lookup field based on a check box field. The apex code runs fine when a single record is edited. The problem comes when integration runs and thousand of records getting updated, the look up field not getting updated. I believe it's when records process during parallel processing the map stores all of the batch records and loop checks for check box flag which is true or false.
map<Boolean,Id> mapCheck = new map<Boolean,Id>();
map<Boolean,Id> ParCheck = new map<Boolean,Id>();
for(Payroll__c pp:newList){
mapCheck.put(pp.Tip__c,pp.id); (Tip is checkbox of child record)
}
for(Payroll p1:[SELECT Id, Entity__c,Tip__c
FROM Service_Catalog_Number_Line__c
WHERE Entity__c=true]){
if( mapCheck.containskey(p1.Tip__c)) {
parCheck.put(p1.Tip__c,p1.id); //Finding parent record that matches with child
}
}
In the above code, mapCheck
gets either true or false for thousand of records and during parallel processing it checks and there will always be both true and false values in MapCheck
. How to solve this. Note: it works perfectly fine if we are updating 1 record or 1 batch but it doesn't work when there are multiple batches run during parallel processing