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
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
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.
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
for more information about context variables please refer to this link
http://raviduttsharma.wixsite.com/salesforce/single-post/2016/04/25/Trigger-Context-Variables
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
//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;
}