You need to sign in to do that
Don't have an account?
SFDC Lightning 18
Data loader wizard after insert records trigger update 200 records only
Hi,
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 upating 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.
Its very urget 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;
}
}
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 upating 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.
Its very urget 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;
}
}