5

I am trying to do some research, and coming across a stumbling block. Execute Anonymous seems to sometimes hit a statement that breaks all further debugs.

system.debug('Statements do appear'); // shows up
try
{
    system.debug(Timezone.getTimeZone('America/New_York')); // never shows up
    throw new DmlException();
}
catch (Exception pokemon)
{
    system.debug(pokemon); // never shows up
}

However, if I change the DmlException above to LimitException, it does throw, so I know the execution is not halted. What's going on?

Logging Levels:

Logging Levels

Even if I change my LoggingLevel on the above debug statements to ERROR, the behavior remains unchanged. But if I change the ApexCode level to FINEST, it works. Why?

8
  • In the Force.com IDE "Execute Anonymous" the debug output does appear in the "Results" window.
    – Keith C
    May 19, 2016 at 19:54
  • @KeithC Interesting, I'll try it in MavensMate.
    – Adrian Larson
    May 19, 2016 at 19:55
  • @KeithC It looks like MM always debugs ApexCode with FINEST, even if I explicitly set it to None.
    – Adrian Larson
    May 19, 2016 at 20:03
  • Try using the "Open Raw Log" from the context menu in the developer console log tab. It should have a header that shows the API version and logging levels that were applied. May 19, 2016 at 20:35
  • For what it is worth, I see both debug messages in the developer console when using a DMLException. May 19, 2016 at 20:36

1 Answer 1

3

TL;DR Looks like a bug to me. Changing the APEX_PROFILING logging level is enough to get the missing debug statements to appear.

The Known Issue is now marked as "FIXED - WINTER '17"


As per the discussion, I've reproduced this in the developer console.

If I set the log levels to only ApexCode: DEBUG and System: ERROR I get the following raw log:

37.0 APEX_CODE,DEBUG;APEX_PROFILING,NONE;CALLOUT,NONE;DB,NONE;SYSTEM,ERROR;VALIDATION,NONE;VISUALFORCE,NONE;WORKFLOW,NONE
Execute Anonymous: system.debug('Statements do appear'); // shows up
Execute Anonymous: try
Execute Anonymous: {
Execute Anonymous:     system.debug(Timezone.getTimeZone('America/New_York')); // never shows up
Execute Anonymous:     throw new DmlException();
Execute Anonymous: }
Execute Anonymous: catch (Exception pokemon)
Execute Anonymous: {
Execute Anonymous:     system.debug(pokemon); // never shows up
Execute Anonymous: }
09:02:05.4 (4345603)|USER_INFO|[EXTERNAL]|005O00000034lD3|[email protected]|New Zealand Standard Time|GMT+12:00
09:02:05.4 (4368694)|EXECUTION_STARTED
09:02:05.4 (4375038)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
09:02:05.4 (4944084)|USER_DEBUG|[1]|DEBUG|Statements do appear

Then changing the APEX_PROFILING to DEBUG and keeping the other levels the same:

enter image description here

37.0 APEX_CODE,DEBUG;APEX_PROFILING,DEBUG;CALLOUT,NONE;DB,NONE;SYSTEM,ERROR;VALIDATION,NONE;VISUALFORCE,NONE;WORKFLOW,NONE
Execute Anonymous: system.debug('Statements do appear'); // shows up
Execute Anonymous: try
Execute Anonymous: {
Execute Anonymous:     system.debug(Timezone.getTimeZone('America/New_York')); // never shows up
Execute Anonymous:     throw new DmlException();
Execute Anonymous: }
Execute Anonymous: catch (Exception pokemon)
Execute Anonymous: {
Execute Anonymous:     system.debug(pokemon); // never shows up
Execute Anonymous: }
09:05:50.3 (3550611)|USER_INFO|[EXTERNAL]|005O00000034lD3|[email protected]|New Zealand Standard Time|GMT+12:00
09:05:50.3 (3572252)|EXECUTION_STARTED
09:05:50.3 (3581418)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
09:05:50.3 (4288210)|USER_DEBUG|[1]|DEBUG|Statements do appear
09:05:50.3 (4702837)|USER_DEBUG|[4]|DEBUG|America/New_York
09:05:50.3 (4930773)|USER_DEBUG|[9]|DEBUG|System.DmlException: Script-thrown exception
09:05:50.4 (4986592)|CUMULATIVE_LIMIT_USAGE
09:05:50.4 (4986592)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

09:05:50.4 (4986592)|CUMULATIVE_LIMIT_USAGE_END

09:05:50.3 (5031944)|CODE_UNIT_FINISHED|execute_anonymous_apex
09:05:50.3 (6112119)|EXECUTION_FINISHED

Raised as Support Case #13877926

I've also encountered some other similar scenarios and have Support Case # 14135299 open. In one case Calling User.Info.getTimeZone() is causing the messages to drop. In another case they just stop appearing for several lines in a CanvasLifecycleHandler and then resume again. In both cases setting the ApexClass logging level to fine got them to appear again.

12
  • 1
    Case #13877926.
    – Adrian Larson
    May 19, 2016 at 21:58
  • 1
    NA20 is on Spring '16 Patch 20.7 versus CS19 on Summer '16 Patch 5.4. So I'd guess that it was something introduced in between those two versions. May 21, 2016 at 4:11
  • 1
    I have replicated this issue in both summer and Spring demo Orgs and I found that the issue is happening with 'Summer Org' and working fine in 'Spring Org'. I will now escalate this case to the Tier3 and will share an update on Monday. We'll see what they say...
    – Adrian Larson
    May 23, 2016 at 20:21
  • 1
    I know have 7 identical comments starting 5/23 that go: This is a follow up on your case #13877926. As I am still waiting for a response from Tier3 and as soon as I get any feedback from their end, I will get back to you... Fun.
    – Adrian Larson
    Jun 2, 2016 at 23:04
  • 1
    @AdrianLarson They could at least put in some effort and rephrase it every now and then. Jun 2, 2016 at 23:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .