0

I'm aiming to update a Contract Date field when the Date field on a corresponding Quote record is changed. The Quote record is linked to the Contract via lookup.

I already have a formula on the Contract object that reads the Quote date. Does this formula get re-evaluated when the Quote is modified? If so, then I can use this as a condition in the trigger.

I want this trigger to run only if a specific Date field on the Quote object is changed. There isn't an ischanged function in Apex I can leverage. How do I design this trigger?

Thank you in advance

1

There is no function like isChanged() in apex trigger. There is an idea which posted in forum for the functionality.

https://success.salesforce.com/ideaview?id=087300000007LI2AAM

However you can check if the value is changed through apex trigger using Trigger.oldMap. You can get lot of example over google. One of the example is here how to use the functionality.

// Check a checkbox only when an Opp is changed to Closed Won!
trigger Winning on Opportunity (before update) {
  for (Opportunity opp : Trigger.new) {
    // Access the "old" record by its ID in Trigger.oldMap
    Opportunity oldOpp = Trigger.oldMap.get(opp.Id);

    // Trigger.new records are conveniently the "new" versions!
    Boolean oldOppIsWon = oldOpp.StageName.equals('Closed Won');
    Boolean newOppIsWon = opp.StageName.equals('Closed Won');

    // Check that the field was changed to the correct value
    if (!oldOppIsWon && newOppIsWon) {
      opp.I_am_Awesome__c = true;
    }
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.