Trigger.oldMap in Apex Trigger

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

 

Note:

This map is only available in update & delete triggers.

    
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: trigger.new) {
            Opportunity oldOpp = new Opportunity();
            oldOpp = oMap.get(newOpp.Id);
            if (newOpp.Amount != oldOpp.Amount) {
                newOpp.Amount.addError('Amount cannot be changed');
                // Trigger Exception 
                } 
            }
        }