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
cmarzillicmarzilli 

Case IsClosed Trigger Bug?

I was testing out some before and after triggers on cases.  When a case goes from a status that is not closed to a status that is closed it will not reflect this change in the trigger.  Basically Trigger.old.IsClosed will equal false (which would be correct) and Trigger.new.IsClosed is false as well (which I feel is incorrect).  I would expect that if the new status is a one that is a closed status Trigger.new.IsClosed would be true.
 
Any thoughts?
mtbclimbermtbclimber
This is not a bug. Currently the setting of this value is not done until the save which comes after the before trigger in the event timeline.

There are two workarounds available for you I believe:

1) Execute your logic in an after trigger. This occurs after the save and thus the value should be set.
2) Query CaseStatus with the value provided by the user for the status to determine if it is flagged as a closed status.

Which one you take would depend on whether you need to modify the object in any way since this is allowed in before triggers but not in after triggers.


cmarzillicmarzilli
Thanks I'll try suggestion #2, I should note however that was experiencing the same thing when using the after trigger so I do not believe suggestion #1 will work.
mtbclimbermtbclimber
Interesting.

This trigger seems to behave as expected (no error):

trigger caseTriggerTestAfter on Case(after update) {
   
    if(trigger.new.status == 'Closed' && !trigger.new.isClosed) trigger.new.status.addError('not closed!');

}

Whereas this one does return the expected "error":

trigger caseTriggerTestAfter on Case(after insert, after update) {
   
    if(trigger.new.status == 'Closed' && trigger.new.isClosed) trigger.new.status.addError('closed!');

}

Is the above not consistent with the behavior you are seeing?