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

  • What is relationship between object and what business functionality you want to achieve? Please elaborate clearly Commented Oct 21, 2022 at 17:21
  • Business logic is Update "parent payroll" lookup field on Payroll child record based on checkbox Tip. A child will have parent only if Tip check box on both child and parent matches. (True-True or False-False.)
    – user97440
    Commented Oct 21, 2022 at 17:37
  • The problem is map of booleans. it stores Tip value of all records during batch processing and there will always be true false during the batch transactions. So the logic mapCheck.containskey(p1.Tip__c) is not quite good.
    – user97440
    Commented Oct 21, 2022 at 17:41
  • Yes your approach is not correct. I have given the answer you can follow those steps Commented Oct 21, 2022 at 17:48

1 Answer 1


In this scenario you need to change your logic. 1- Create set of parentId by traversing on newList. 2- Create a map Map<ParentId,ParentTip>by querying parentRecord where Id In set that you created in step 1. 3- At last you can traverse to newlist again and check Tip value of parent based on step 2 map and match with childRecord Tip in newList value and do your logic.

  • Hey Prajjwal, thanks for this. In Step1 : how do we find parentids as the find parent logic is a combination of these major__c=true,pecode__c should be same as child and tip should be same as child. Then we call that a parent and assign. Sorry I was not clear earlier about this.
    – user97440
    Commented Oct 21, 2022 at 18:20
  • Okay so instead of Set of ParentId Create a set to store all Pecode. And step 2 query all parent having major = true and pecode in Set of step 1. Now step 2 Map will be now Map<String,Id> string will be combination of pecode+tip.Based on this when you traverse on newlist again find the combination of pecode and tip of child record and assign parent Id based on map of step2 Commented Oct 21, 2022 at 18:36
  • Here is the code I updated. I don't know what else is wrong here.
    – user97440
    Commented Oct 21, 2022 at 18:58
  • I can't see updated code Commented Oct 22, 2022 at 2:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .