+ Start a Discussion
SFDC Lightning 18SFDC Lightning 18 

Trigger help not updating after 200 records

Hi Team,

My client using data import wizard to insert the records Max 1000 records, after inserting records backend trigger is executed only 200 records remaining records not updating showing EHR_TS__c Null values, But when I use data loader tool trigger is working fine & updating all the records same CSV file I am using.

It's very urgent for me, if anybody can please help me on this highly appreciative.

Below is the code i am using.

***************************** TRIGGER **************************************************
Trigger UpdateEHRate on Time_Sheet__c (before insert,before update,after update, after insert)
{        

try {
         
    if((Trigger.isInsert && Trigger.isAfter) || (Trigger.isUpdate && Trigger.isAfter)){   
        if(checkRecursive.isFirstRun()){

            List<Time_Sheet__c> timeList = EHRTriggerHandler.UpdateEHRate(trigger.New);
            if(timeList.size() > 0){
                //update timeList;
                Database.update(timeList, false);
            }
        } 
    }
}
catch(DmlException de) {
System.debug('--->The following DMLexception has occurred: ' + de.getMessage());
Integer numErrors = de.getNumDml();
    System.debug('---->getNumDml=' + numErrors);
    for(Integer i=0;i<numErrors;i++) 
    {
        System.debug('--->getDmlFieldNames=' + de.getDmlFieldNames(i));
        System.debug('--->getDmlMessage=' + de.getDmlMessage(i));  
    }
}
catch(Exception e) {
System.debug('--->The following exception has occurred: ' + e.getMessage());
}
}

**************************** APEX CLASS  **********************************************

public class EHRTriggerHandler{
    
    public static List<Time_Sheet__c> UpdateEHRate(List<Time_Sheet__c> lstTS){ 
       List<Time_Sheet__c> timeList = new List<Time_Sheet__c>();
        System.debug('@@@@@@@1'+timeList);
       set<Id> TSIds = new set<Id>();
       Map<Id ,boolean> mapTimeSheet = new Map<Id,boolean>();
        for(Time_Sheet__c EHR : lstTS) {    
            TSIds.add(EHR.Employee__c);
        }                       
        
        List<Estimated_Hourly_Rate__c> EHRlist = [SELECT Id, Name,Employee__c,Start_Date__c,End_Date__c,Estimated_Hourly_Rate_Variable__c 
                                              FROM Estimated_Hourly_Rate__c 
                                              WHERE Employee__c =:TSIds];  
        
        Map<id,List<Estimated_Hourly_Rate__c>> mapEs = new Map<id,List<Estimated_Hourly_Rate__c>>();
        
        for (Estimated_Hourly_Rate__c c : EHRlist) {
                List<Estimated_Hourly_Rate__c> l = mapEs.get(c.Employee__c);
                if (l == null) {
                    l = new List<Estimated_Hourly_Rate__c>();
                    mapEs.put(c.Employee__c, l);
                }
            l.add(c);
        }
        
        boolean isMatchFound = false;        
        //if(EHRlist!=null && !EHRlist.isEmpty()) {
         for(Time_Sheet__c timeSheetRec :lstTS){
             Time_Sheet__c timee = new Time_Sheet__c();  
             
             List<Estimated_Hourly_Rate__c> listes = mapEs.get(timeSheetRec.Employee__c);
            for(Estimated_Hourly_Rate__c EHR : listes) {   
                     if(timeSheetRec.Record_Date__c >= EHR.Start_Date__c && timeSheetRec.Record_Date__c <= EHR.End_Date__c ){                    
                        timee.id = timeSheetRec.id;
                        timee.EHR_TS__c = EHR.Estimated_Hourly_Rate_Variable__c; 
                        //timeSheetRec.EHR_TS__c = EHR.Estimated_Hourly_Rate_Variable__c;  
                        isMatchFound = true;
                        
                    } 
                }
                
                 timeList.add(timee);              
            }  
          //}             
           
        if(!isMatchFound){
            lstTS[0].addError('The given Record date does not fall under any of the Estimated Hourly Rates record(s)');
        }
        
        return timeList;
  }  
}
Steven NsubugaSteven Nsubuga
In your trigger, I notice that you have if(checkRecursive.isFirstRun()) . At what point do you ever set the value to false?
That is, when does CheckRecursive.isfirstRun()=false ?
SFDC Lightning 18SFDC Lightning 18
****** CheckRecursive Apex Class********
public class checkRecursive {
    
    public static boolean firstRun = true;
    public static boolean isFirstRun(){
    if(firstRun){
      firstRun = false;
      return true;
    }else{
        return firstRun;
    }
    }
}
SFDC Lightning 18SFDC Lightning 18
Hi Steven Nsubuga,

I Comment the check Recursive code block, same issue I am facing...