You need to sign in to do that
Don't have an account?
Tanya Shah
How to find date difference
I've written a trigger to update product dates.There are number of products added to particular opportunity and each one has different ServiceDate . So I want to add the difference (service date - Opportunity.closeDate) to each of them so that every product service date is pushed to a new date with difference equal to the number of days between service date and close date.
Please help !
Please help !
trigger productUpdate on Opportunity (after update) { // declare list to hold opportuity line item OpportunityLineItem[] olis = [SELECT Id, Name, ServiceDate, Opportunity.CloseDate FROM OpportunityLineItem WHERE OpportunityId IN :Trigger.New]; for(OpportunityLineItem oli : olis ){ // perform logic to bumb date somehow... //oli.ServiceDate = oli.Opportunity__r.CloseDate + (10); Integer dat=oli.ServiceDate.day(); System.debug('dat prod '+ oli + dat); Integer dot=oli.Opportunity.CloseDate.day(); System.debug('opp cd '+ dot); Integer diff=dat-dot; // integer diff = dat.daysBetween(dot); System.debug('diff'+ diff); oli.ServiceDate = Trigger.newMap.get(oli.OpportunityId).CloseDate.addDays(diff); } update olis; }
Example: See this :
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_date.htm#apex_System_Date_daysBetween
In my case i have to update Product Service dates based on Opportunity Close date . Thank you !