function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tanya ShahTanya Shah 

trigger to update dates

I want to write a trigger to Update product dates when opp close date changes .
There are number of products added to particular opportunity and each one has different ServiceDate .Following is what i tried ,
 
trigger productUpdate on Opportunity (after update) {
		
	OpportunityLineItem[] olis = [SELECT OpportunityId, ServiceDate, Opportunity.CloseDate FROM OpportunityLineItem WHERE OpportunityId IN :Trigger.New];
    for(OpportunityLineItem oli :olis)
     {

      oli.ServiceDate = Trigger.newMap.get(oli.OpportunityId).CloseDate.addDays(oli.ServiceDate.daysBetween(oli.Opportunity.CloseDate));
   
     }
	update olis;

 }
This is working but not giving me improper dates . Something random . I want to refer to below link to get it to similar way

http://thysmichels.com/2012/04/10/salesforce-update-product-schedule-from-opportunity-product-using-apex-trigger/

Thank you !
Shashikant SharmaShashikant Sharma
Could you share some input and there expected and actual output.
Tanya ShahTanya Shah
Want to explain a scenario . For eg,When we go to showroom, they say BMW(Prod 1)  will get in next 100 days , then Audi(Prod 2) in 50 days , Activa(Prod 3) in 20 days etc . This all will be while updating  Opportunity close date . It should be different dates for diff products likewise .Thank you !