+ Start a Discussion
sandeep@devsandeep@dev 

before trigger not updating records

Hi Guys below is my trigger,

trigger AgenciesCommission on Invoice_Line_Item__c (before Insert, before update) 
{

for(Invoice_Line_Item__c Ili: Trigger.New)
{
    Ili.Total_Agencies_commission__c=Ili.Agencies_commission__c;
    Ili.Gst_Amount__c=Ili.Total_Gst_Amount__c;
      
}

//Sandeep : To Update Days overflown to previous month functionality   : START
    
    if(trigger.isbefore )
        {
        if(triggerHelperRecursiveCheck.runOnce==true){
            map<string,integer> differentStartEndDateMap = new  map<string,integer>();
            set<Id> siteIds = new set<Id>();
            for(Invoice_Line_Item__c invLnItem: trigger.new)
            {
                if(invLnItem.Startdate__c.month() != invLnItem.EndDate__c.month()){
                    if(differentStartEndDateMap.get(String.valueOf(invLnItem.SiteName__c).substring(0, 15)+string.valueOf(invLnItem.EndDate__c.month())+string.valueOf(invLnItem.EndDate__c.year())) == null){
                        differentStartEndDateMap.put(String.valueOf(invLnItem.SiteName__c).substring(0, 15)+string.valueOf(invLnItem.EndDate__c.month())+string.valueOf(invLnItem.EndDate__c.year()),invLnItem.EndDate__c.day());
                    }                   
                }
                if(String.valueOf(invLnItem.SiteName__c).substring(0, 15) != null){
                    siteIds.add(String.valueOf(invLnItem.SiteName__c).substring(0, 15));
                }
            }
            map<string,integer> differentStartEndDateMapTemp = differentStartEndDateMap.clone();
            for(Invoice_Line_Item__c invLnItem: trigger.new)
            {
                if(differentStartEndDateMapTemp != null && differentStartEndDateMapTemp.get(String.valueOf(invLnItem.SiteName__c).substring(0, 15)+string.valueOf(invLnItem.Startdate__c.month())+string.valueOf(invLnItem.Startdate__c.year())) != null){
                    invLnItem.days_Overflow_from_Previous_Month__c = differentStartEndDateMapTemp.get(String.valueOf(invLnItem.SiteName__c).substring(0, 15)+string.valueOf(invLnItem.Startdate__c.month())+string.valueOf(invLnItem.Startdate__c.year()));
                    differentStartEndDateMapTemp.remove(String.valueOf(invLnItem.SiteName__c).substring(0, 15)+string.valueOf(invLnItem.Startdate__c.month())+string.valueOf(invLnItem.Startdate__c.year()));
                }              
            }
            
            //updating Existing Records for days_Overflow_from_Previous_Month__c value - Start.
            differentStartEndDateMapTemp = differentStartEndDateMap.clone();
            if(siteIds != null && !siteIds.isEmpty()){
            System.debug('@@@@ KeySet'+differentStartEndDateMapTemp.keyset());
                list<Invoice_Line_Item__c> listinvLnItemsWithSiteIds =[select Name,Startdate__c,EndDate__c,Days_Inv_nxt_mnth__c,MMYYYYENDDATE__c,SiteName__c,SiteID_MMYYYYSTARTDATE__c from Invoice_Line_Item__c where SiteName__c IN : siteIds and SiteID_MMYYYYSTARTDATE__c in :differentStartEndDateMapTemp.keyset()];
                System.debug('#######'+listinvLnItemsWithSiteIds);
                if(listinvLnItemsWithSiteIds != null && !listinvLnItemsWithSiteIds.isEmpty()){
                    for(Invoice_Line_Item__c invLnItem: listinvLnItemsWithSiteIds)
                    {
                        if(differentStartEndDateMapTemp != null && differentStartEndDateMapTemp.get(String.valueOf(invLnItem.SiteName__c).substring(0, 15)+string.valueOf(invLnItem.Startdate__c.month())+string.valueOf(invLnItem.Startdate__c.year())) != null){
                            invLnItem.days_Overflow_from_Previous_Month__c = differentStartEndDateMapTemp.get(String.valueOf(invLnItem.SiteName__c).substring(0, 15)+string.valueOf(invLnItem.Startdate__c.month())+string.valueOf(invLnItem.Startdate__c.year()));
                            differentStartEndDateMapTemp.remove(String.valueOf(invLnItem.SiteName__c).substring(0, 15)+string.valueOf(invLnItem.Startdate__c.month())+string.valueOf(invLnItem.Startdate__c.year()));
                        system.debug('$$$$$$$$$$$$$$$$$$'+invLnItem.days_Overflow_from_Previous_Month__c);                        
                        }                           
                        
                    }
                    
                }
                triggerHelperRecursiveCheck.runOnce=false;
                //update listinvLnItemsWithSiteIds;
                
            }
            //updating Existing Records for days_Overflow_from_Previous_Month__c value - End.
        }
    }
    //Sandeep : To Update Days overflown to previous month functionality : END
}

I'm not getting any error, i've also debugged ut it's assigning the value for " invLnItem.days_Overflow_from_Previous_Month__c " in debug also, but not updating the records. 

can anyone please suggest me y it's not.

Thanks in Advance,
Sandeep Kumar
sandeep@devsandeep@dev
I didn't kept any DML statements Manish, iknow that, but the records are not updating even aeverything is right, that's my issue. anyone can debug the code and help me is greatly appreciated.

Thanks
sandeep@devsandeep@dev
I didn't kept any DML statements Manish, iknow that, but the records are not updating even aeverything is right, that's my issue. anyone can debug the code and help me is greatly appreciated.

Thanks