You need to sign in to do that
Don't have an account?
Linda 98
System limit execption:cpu time limit exceeded in trigger.
hi i am getting this error in my trigger when i execute 100 records or so.works fine for records less than tht.
pls help
for(integer c=0;c<dt.size()-1;c++) { TDays=TDays+dt[c].daysBetween(dt[c+1]); }
pls help
trigger Accforet on Opportunity (after insert,after update) { List<Acc__c> AccproductList =new List<Acc__c>(); List<Opportunitylineitem> opplinitemlist =new List<Opportunitylineitem>(); list<opportunitylineitem > oppdate= new list<opportunitylineitem >(); List<Acc_Product_Fcst__c> accquery =new List<Acc_Product_Fcst__c>(); List<date> dt =new List<date>(); Set<Id> sProductIds = new Set<Id>(); Set<Id> sAccountIds = new Set<Id>(); Set<id> saccprodfcstids =new set<Id>(); Acc__c accpro =new Acc___c(); string aname; Integer i; Integer myIntMonth; Integer myIntyear; Integer myIntdate; opplinitemlist=[select Id,PricebookEntry.Product2.Name,opp_account__c,Opp_account_name__c,PricebookEntry.Product2.id, quantity,ServiceDate,Acc_Product_Fcst__c from Opportunitylineitem WHERE Opportunityid IN :Trigger.newMap.keySet() AND Acc_product_fcst__c='']; for(OpportunityLineItem oli:opplinitemlist) { sProductIds.add(oli.PricebookEntry.Product2.id); sAccountIds.add(oli.opp_account__c); //saccprodfcstids.add(oli.Acc_Product_Fcst__c); System.debug('************oli:'+oli); } accquery=[select id,Total_Qty_Ordered__c,Last_Order_Qty__c,Last_Order_Date__c,Fcst_Days_Period__c from Acc__c where Acc__c.product__c In :sproductids and Acc___c.Account__c in :saccountids]; System.debug('*****accquery:'+accquery); for(Acc__c apf1 :accquery){ saccprodfcstids.add(apf1.id); } if(saccprodfcstids!=null){ oppdate=[select servicedate from opportunitylineitem where Acc_Product_Fcst__c IN :saccprodfcstids ]; i =[select count() from Opportunitylineitem where acc__c in :saccprodfcstids]; } System.debug('************Trigger.new:'+trigger.newmap.keyset()); System.debug('************sproductsIds:'+sProductIds); System.debug('************saccountIds:'+sAccountIds ); System.debug('************saccprodfcstids:'+saccprodfcstids); System.debug('************accquery:'+accquery); System.debug('************oppdate:'+oppdate); system.debug('************i:'+i); for(Opportunity opp :trigger.new) { if(opp.Stagename=='Closed Won') { for(opportunitylineitem opplist:opplinitemlist) { if(!accquery.isempty()) { for(opportunitylineitem opldt :oppdate) { string myDate = String.valueOf(opldt); myDate = myDate.substring(myDate.indexof('ServiceDate=')+12); myDate = myDate.substring(0,10); String[] strDate = myDate.split('-'); myIntMonth = integer.valueOf(strDate[1]); myIntYear = integer.valueOf(strDate[0]); myIntDate = integer.valueOf(strDate[2]); Date d = Date.newInstance(myIntYear, myIntMonth, myIntDate); dt.add(d); } dt.add(opp.closedate); dt.sort(); integer TDays=0; for(integer c=0;c<dt.size()-1;c++) { system.debug('*******tdays:'+tdays); TDays=TDays+dt[c].daysBetween(dt[c+1]); system.debug('*******tdays:'+tdays); System.debug('*******dt:'+dt); } for(Acc__c apf:accquery) { apf.Fcst_Days_Period__c = TDays/i; apf.Total_Qty_Ordered__c =apf.Total_Qty_Ordered__c +opplist.quantity; apf.Last_Order_Qty__c=opplist.quantity; apf.Last_Order_Date__c=opp.CloseDate ; apf.Fcst_Qty_Avg__c=apf.Total_Qty_Ordered__c/(i+1); Opplist.Acc_Product_Fcst__c =apf.Id; } // update opplist; // update accquery; } else{ accpro.Account__c=opplist.opp_account__c; accpro.product__c=opplist.PricebookEntry.Product2.Id; accpro.opplineitemid__c=opplist.id; accpro.Total_Qty_Ordered__c =opplist.quantity; accpro.Last_Order_Qty__c=opplist.quantity; accpro.Last_Order_Date__c=opp.CloseDate; accpro.Fcst_Qty_Avg__c=opplist.quantity; accpro.Fcst_Days_Period__c=7; accproductList.add(accpro); system.debug('********accpro:'+accpro); system.debug('********accproductlist:'+accproductlist); } insert accproductlist; } update opplinitemlist; update accquery; } } }
I wrote the soql outside for loop only..
but i had update statements inside for loop.
I just removed them outside and stil i get the same error at same lines.
Please help me ..
Its a urgent issue.:(
please
trigger AccountAfterUpdate on Account (after update) {
AccountUpdateManager.doAfterUpdate(Trigger.newMap, Trigger.oldMap);
}
:(