Hacking the APEX Debugger

You like the build-in APEX Debugger which you can be activated through the Developers Toolbar?

All links which APEX is generating when rendering the page contain the debug flag too. But when you enter something into a form and press the submit button or any other button, the Debug mode is disabled and you don’t see what APEX is doing to process the data.

It’s time to “hack” the APEX debugger!

  • Go to Shared Components and create two Application Items named APEXLIB_SAVED_DEBUG and APEXLIB_SAVED_REQUEST
  • Create a new Application Process with the following settings
    • Name: ApexLib_SaveRequest
    • Sequence: 1
    • Point: On Submit – After Page Submission – Before Computations and Validations
    • Process Text:
    • Process Error Message: #SQLERRM#
  • Create another Application Process with the following settings
    • Name: ApexLib_EnableDebugMode
    • Sequence: 1
    • Point: On Load – Before Header (page template header)
    • Process Text:
             IF :APEXLIB_SAVED_DEBUG = 'YES'
                 WWV_Flow.g_debug := TRUE;
             END IF;
         END IF;
    • Process Error Message: #SQLERRM#

That’s it, when you now active the Debug Mode by clicking into the Developer Toolbar, the debug mode setting will also stay when you press a button to submit the page.

Now you see how APEX is processing your changed data and which branches are firing.

Background information

What does the code do?

  1. First it stores the current REQUEST information into a field, because after the data has been processed a redirect occurs which clears the info in the :REQUEST bind variable, but we need that info.
  2. In the second process (on-load) we check if the page has been called with a request. For page calls with an URL link the request is always null. So if it’s a REQUEST call we use our stored value from the last page rendering (where the debug flag is contained in the URL).

Happy debugging!


As Vikas was pointing out on the OTN forum, the hack is only useful for pre-2.2 APEX versions, because APEX 2.2 had an enhancement in that area.