Skip to main content
In Opportunity, If the stage is changed from another value to CLOSED_WON or CLOSED_LOST,populates the Close Date field with Today().
3 Antworten
  1. 8. Juli 2015, 08:00
    Hello Saurav,

    This code update close date  

    trigger changeStage on Opportunity (after update) {

    list<Opportunity> listOfOpportunity = [select Id,stageName,CloseDate from Opportunity where ID IN : trigger.new];

    list<Opportunity> tempListOfOpportunity= new list<Opportunity>();

    for(Opportunity oppNew :listOfOpportunity)

    {

    if(oppNew.StageName!=trigger.oldMap.get(oppNew.id).stageName)

    {

    if(oppNew.stageName.equalsIgnoreCase('Closed Won') || oppNew.stageName.equalsIgnoreCase('Closed Lost'))

    {

    oppNew.CloseDate = Date.today();

    tempListOfOpportunity.add(oppNew);

    }

    }

    }

    update tempListOfOpportunity;

    }

    Thanks.

     
0/9000