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
Raghav Sharma 39Raghav Sharma 39 

Can we use old and oldMap context variables in after update event in trigger?

Best Answer chosen by Raghav Sharma 39
sfdc13sfdc13
Yes, we can write trigger.old and trigger.oldMap in after update triggers 
for more information about context variables please refer to this link
http://raviduttsharma.wixsite.com/salesforce/single-post/2016/04/25/Trigger-Context-Variables

All Answers

pranaya bhoyarpranaya bhoyar
Yes we can use trigger.old and trigger.oldMap in after update.
sfdc13sfdc13
Yes, we can write trigger.old and trigger.oldMap in after update triggers 
for more information about context variables please refer to this link
http://raviduttsharma.wixsite.com/salesforce/single-post/2016/04/25/Trigger-Context-Variables
This was selected as the best answer
Raghav Sharma 39Raghav Sharma 39
Pranaya, Suresh : But since the record is already deleted , how will we get the Id for the record ?
sfdc13sfdc13
U can retrieve from the recycle bin,deleted records will be moved to the recycle bin and available for 15 days in the database
sagar jogisagar jogi
You can access Trigger.old and Trigger.oldmap in after update trigger
However you can't access Trigger.old is before insert trigger. You will also not get trigger.oldmap in before insert trigger, because Trigger.oldmap is having key = record id and value = sObject. So in before insert record will not be inserted into database and key will be null for trigger.oldmap

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks and Regards,
Sagar Jogi
Raghav Sharma 39Raghav Sharma 39
Thank you every one. I am posting my code for others 


//After deleting an opportunity update the related account   
trigger updateOpportunity on Opportunity (after delete) {
    
 
    List<Id> accIdList= new List<Id>();
    List<Account> accList=new List<Account>();
    for(Opportunity opp:Trigger.old){    
         accIdList.add(opp.AccountId);
    }
 
    List<Account> accc=[Select id,Phone from Account where Id IN :accIdList ];
    for(Account acc: accc){
         acc.Phone='0';
         accList.add(acc);
    }
    
    if(accList.size()>0)
    update accList;    
    
}