You need to sign in to do that
Don't have an account?
Ramesh Varatharaj
oppotunitylineitemschedule resetting scheduledate based on servicedate
Hi Team, I have written a code to reset the schedule date whenever the opportunityproductlineitem's service date gets updated. I am coming across an issues - assume opportuntiy has 5 productlineitem and when i edit the servicedate from "editall" page, the system triggers the scheduledate updates only for the last productlineitem's realted schedules - ie the last item in the product. But the updated servicedate gets saved for all the product line item, but the trigger to update the lineitem's schedule is getting triggered only for the last product. But when i go and just click "Edit" and "Save" for other products individually, the schedule gets updated.
Any idea why this is happening? Thanks
Any idea why this is happening? Thanks
trigger lineitemschedule1 on OpportunityLineItem (after Insert ,after Update) {
List<OpportunityLineItemSchedule> itemscheduleA = new List<OpportunityLineItemSchedule>();
if(Trigger.isUpdate){
for(OpportunityLineItem p: trigger.New) {
OpportunityLineItem pOld= Trigger.oldMap.get(p.Id);
Date dt= p.ServiceDate;
Integer mon=dt.month();
Integer d=dt.day();
Integer y=dt.year();
Integer DaysInMonth=date.daysInMonth(y,mon);
boolean flag=false;
Date dt1 = date.newInstance(y,mon,d);
Date dt2 = date.newInstance(y,mon+1,1);
Integer i =1 ;
itemscheduleA.clear();
itemscheduleA=[Select id, ScheduleDate from OpportunityLineItemSchedule where OpportunityLineItemId =: p.Id ORDER BY ScheduleDate ASC];
for(OpportunityLineItemSchedule rs : itemscheduleA) {
if(flag==false) {
rs.ScheduleDate =dt1;
flag = true;
}
else {
rs.ScheduleDate =dt2;
dt2 = dt2.addMonths(i);
}
}
}
}
update itemscheduleA;
}