1

Creating a record (of a custom sObject) when the record type is changed (by the user) on the Case record. Org has a variety of Process Builder and Workflows and the trigger is running twice. This is expected behavior. However for some reason the Trigger.Old RecordTypeId value is still the old record type id on the second trigger execution. If other fields are updated by the workflow/process builder then the trigger rerun should have the new RecordTypeId in trigger.old on the second trigger execution (and therefore my check to see if RecordTypeId changed should be false). My question is, is what I said in the previous sentence expected behavior or is the Trigger.Old RecordTypeId being the same in both trigger executions the expected behavior?

4

It's behavior that I wish weren't the case (though having it behave the intuitive way would probably lead to other problems), but it is known and expected.

Trigger.old and Trigger.oldMap do not have their values updated when a field update action causes update triggers to be run again.

This is covered in the documentation:

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 doesn’t contain the version of the object immediately before the workflow update, but the object before the initial update was made. For example, suppose that 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.

2
  • Thank you Derek!
    – Bobbygllh
    Oct 5 '20 at 16:19
  • 1
    @PhilW Thanks for adding the documentation. I was trying to find it, but couldn't.
    – Derek F
    Oct 5 '20 at 17:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.