I spent quite some time debugging an issue because the stack trace line numbers were not correct and wanted to share my findings. The problem seems to be 10 Years old and fixed, but under specific circumstances, it seems to be still a problem.
I am able to reproduce it, but I'm not able to reproduce it with custom code only.
Run this in anonymous apex:
System.debug(1);
if(Trigger.isBefore) {
System.debug(2);
}
It will fail in line 1. (The latest thing that happens before line 3, where the Exception originates from).
I totally get why it is thrown (the flag is null), but to find out that this was the issue took me hours if not a day because I spent all the time debugging line 1 instead of 3. Frustrating. I am not able to reproduce this by creating my own nullish flags as it was done in the 10 years old post. if(nullFlag)
leads to correct line numbers, only the Trigger.flags
are leading to wrong stack trace line numbers (is the internal Trigger class running on a super old API version??).
Also Setting the logging Level to FINEST does not solve it (as it solved it back then).
Should I create a case, or is this just a thing that will never be fixed? does anyone have any insights about the fixing progress of the old issue?
UPDATE
I created a case and the SF support is working on it. I asked for any public reference, but there is none. I will try to test it once in a while and keep you updated. Their statement:
We assure you that issue will be resolved and we currently linked the BUG to this case number with high priority as reference.
Currently, as per salesforce policies the Known Issue article will not be created on a Single Incident as further more customers reach to us raising the incident the Known Issue will be created on approval of the higher team to track it further.
Trigger.isExecuting
only then use Trigger context variables.