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 product date

I want to write a trigger to Update product dates when opp close date changes .
 
For eg.
Opportunity Close Date:  11/29/2014    (Nov 29th 2014)
Prod 1 Start Date :   12/9/2014   (10 days from Opportunity Close date)
Prod 2 Start Date:    12/23/2014  (22 days from opportunity close date)

Please help. Thanks in advance .
textualtextual
i think you referring to OpportunityLineItems
Have you written a trigger before?
Heres some untested code:
 
trigger productUpdate on Opportunity (after update) {
	
	// declare list to hold opportuity line item
	List<OpportunityLineItem> olis = new List<OpportunityLineItem>();

	// declare a set to hold opporrunity ids
	// loop through trigger to get all ids of updated opportuniities
	Set<Id> Ids = new Set<Id>();

	// fetch all line items for the opportnities updated order by opportunitiy id
	olis = [SELECT Id, Name, Start_Date__c, Opportunity__r.CloseDate FROM OpportnuityLineItem WHERE OpportunityId IN :Ids];

	//loop through line items
	for(OpportunityLineItem oli : olis ){
		// perform logic to bumb date somehow...
		oli.Start_Date__c = oli.Opportunity__r.CloseDate + (???);
	}
	update olis;

}

 
Tanya ShahTanya Shah
Trying for the first time. Not able to fire query . It says sObject type 'OpportnuityLineItem' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name.. 

Please help.Thanks again .
textualtextual
the code I wrote is just something to get you started, it's not really going to work. the error you got is because I spelled opportunity wrong