Activity › Forums › Salesforce® Discussions › Does trigger.oldmap change during recursion in Salesforce?
Tagged: Multiple Loops, Recursion, Salesforce Record, Salesforce Trigger, Trigger Old, Trigger OldMap, Workflow Rule
-
Does trigger.oldmap change during recursion in Salesforce?
Posted by madhulika shah on August 16, 2018 at 1:16 PMDoes trigger.oldmap change during recursion in Salesforce?
shariq replied 7 years, 9 months ago 4 Members · 3 Replies -
3 Replies
-
Hi Madhulika,
Trigger.old contains a version of the objects before the specific update that fired the trigger. However, there is an exception. When a record is updated and subsequently triggers a workflow rule field update, Trigger.old in the last update trigger won’t contain the version of the object immediately prior to the workflow update, but the object before the initial update was made. For example, suppose an existing record has a number field with an initial value of 1. A user updates this field to 10, and a workflow rule field update fires and increments it to 11. In the update trigger that fires after the workflow field update, the field value of the object obtained from Trigger.old is the original value of 1, rather than 10, as would typically be the case.
Based on that, I think Trigger.old will maintain the original value even throughout multiple loops through the order of execution due to recursionthanks.
- [adinserter block='9']
-
Hi
Trigger.old contains a version of the objects before the specific update that fired the trigger. However, there is an exception. When a record is updated and subsequently triggers a workflow rule field update, Trigger.old in the last update trigger won’t contain the version of the object immediately prior to the workflow update, but the object before the initial update was made. For example, suppose an existing record has a number field with an initial value of 1. A user updates this field to 10, and a workflow rule field update fires and increments it to 11. In the update trigger that fires after the workflow field update, the field value of the object obtained from Trigger.old is the original value of 1, rather than 10, as would typically be the case.
Based on that, I think Trigger.old will maintain the original value even throughout multiple loops through the order of execution due to recursion -
Hi,
To explain more –
Let me explain it with an example. Let say you have a requirement where you want to save the previoues owner of an account when the account owner is changed. You understand that you need to create a trigger on update for account. Let say you click edit button and the owner is abc. Now you need to check that if owner is changed whehter it is defferent from previuos one.Here comes the need of trigger.oldmap. You check that if the new entered owner let say xyz is same of diffrent from the previous owner. You can do that trigger.oldmap.account.owner(abc)== trigger.newmap.account.owner (xyz)..(just an example as this is not the right way to access account owner field).
In the above example, you can make out that oldmap and newmap is used to compare the old and new versions of Sobject records.
Hope this helps.
Log In to reply.