A map of IDs to the old version of the sObject records.

trigger ApexTrigger on Opportunity (before update) {

    // Only available in Update and Delete Triggers

    Map<Id,Opportunity> oMap = new Map<Id,Opportunity>();

    oMap = trigger.oldMap;

    for(Opportunity newOpp :


        Opportunity oldOpp = new Opportunity();

        oldOpp = oMap.get(newOpp.Id);

        if(newOpp.Amount != oldOpp.Amount)


            newOpp.Amount.addError(‘Amount cannot be changed’); // Trigger Exception




Note: This map is only available in update & delete triggers.

Our Recent Blog

Share This Post