function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Deepu sfdcDeepu sfdc 

difference between trigger.old and trigger.oldmap

Best Answer chosen by Deepu sfdc
JyothsnaJyothsna (Salesforce Developers) 
Hi Deepu,


Trigger.old: Returns a list of the old versions of the sObject records.
Note that this sObject list is only available in the update and delete triggers.
 
Trigger.oldMap: A map of IDs to the old versions of the sObject records.Note that this map is only available in the update and delete triggers.  
 

suppose you have a custom object Custom_obj__c

Trigger.old means it is a List<Custom_obj__c>
 

and

Trigger.oldMap means it is a map<Id, Custom_obj__c>

 
 
 
Best Regards,
Jyothsna

All Answers

JyothsnaJyothsna (Salesforce Developers) 
Hi Deepu,


Trigger.old: Returns a list of the old versions of the sObject records.
Note that this sObject list is only available in the update and delete triggers.
 
Trigger.oldMap: A map of IDs to the old versions of the sObject records.Note that this map is only available in the update and delete triggers.  
 

suppose you have a custom object Custom_obj__c

Trigger.old means it is a List<Custom_obj__c>
 

and

Trigger.oldMap means it is a map<Id, Custom_obj__c>

 
 
 
Best Regards,
Jyothsna
This was selected as the best answer
VineetKumarVineetKumar
Additionaly :

Trigger.Old : This sObject list is only available in update and delete triggers.
Trigger.oldMap: This map is only available in update and delete triggers.
Veena GopalVeena Gopal
which is better? using Trigger.Old or Trigger.oldMap. if suppose i am comparing between 2 values.one old and one new to check if the value is changed. mostly old map is used but i feel trigger.old can also be used.
Rajesh Ch 4Rajesh Ch 4
Veena, perhaps it is too late to answer your question, but this is for others who want to know the answer. 
as you mentioned, people mostly use trigger.oldMap, because ther order of records in trigger.new & trigger.old might be different, so there is no gaurantee you refer to the same record while comparing (trigger.old[i] & trigger.new[i] might be different records), but if you use trigger.oldMap, you can get the old version of record using ID, hence we can gaurantee the record is same.
Hope it clarifies your doubt.

Ex:- (code copied from other article)
//Comparing whether Stage has been changed or not

for(Opportunity opp:Trigger.New){
    if(opp.Stage != Trigger.oldMap.get(opp.Id).Stage){
        //Your logic
    }
}