• Mario Conteddu 11
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Here is what I need to achieve:
track how many times BDM_Projected_Launch_Date__c gets changed in Count_of_PLD_changes__c
calculate difference in months between the very first BDM_Projected_Launch_Date__c and last one in of_Months_since_1st_PLD__c
the very first BDM_Projected_Launch_Date__c value is recorded on PLD_first_Value__c and it gets populated at record creation by a WFR

here is what I've done so far but it's not really working.
trigger ProjectedLiveDateTracking on Opportunity (before update) {

  Map<Id,Opportunity> o = new Map<Id,Opportunity>();
  
    o = trigger.oldMap;
    
    for(Opportunity newopp: trigger.new)
    {
        
        
        if(newopp.BDM_Projected_Launch_Date__c != o.get(newopp.Id).BDM_Projected_Launch_Date__c)
        
        {
        
        Date old = o.get(newopp.Id).PLD_first_Value__c;
        Date first = newopp.BDM_Projected_Launch_Date__c;
        Integer monthDiff = old.monthsBetween(first);
        if (first.day() > old.day()) monthDiff++;
        System.debug(monthDiff);
        newopp.of_Months_since_1st_PLD__c = monthDiff;
        newopp.Count_of_PLD_changes__c++;

        }
        
    }
}



 
Here is what I need to achieve:
track how many times BDM_Projected_Launch_Date__c gets changed in Count_of_PLD_changes__c
calculate difference in months between the very first BDM_Projected_Launch_Date__c and last one in of_Months_since_1st_PLD__c
the very first BDM_Projected_Launch_Date__c value is recorded on PLD_first_Value__c and it gets populated at record creation by a WFR

here is what I've done so far but it's not really working.
trigger ProjectedLiveDateTracking on Opportunity (before update) {

  Map<Id,Opportunity> o = new Map<Id,Opportunity>();
  
    o = trigger.oldMap;
    
    for(Opportunity newopp: trigger.new)
    {
        
        
        if(newopp.BDM_Projected_Launch_Date__c != o.get(newopp.Id).BDM_Projected_Launch_Date__c)
        
        {
        
        Date old = o.get(newopp.Id).PLD_first_Value__c;
        Date first = newopp.BDM_Projected_Launch_Date__c;
        Integer monthDiff = old.monthsBetween(first);
        if (first.day() > old.day()) monthDiff++;
        System.debug(monthDiff);
        newopp.of_Months_since_1st_PLD__c = monthDiff;
        newopp.Count_of_PLD_changes__c++;

        }
        
    }
}