You need to sign in to do that
Don't have an account?
cmarzilli
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?
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.
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?