Oracle APEX Blog

APEX Developer Mode

Written by Matt Mulvaney | Mar 8, 2018 11:42:31 AM

When I used to work with Oracle Forms, the company I worked for used to grant users on the development environment with a special role which provided enhanced access to many areas of the system. The name of this role was called… GOD MODE.

This was only ever applied to the development system and it was a big help when supporting and developing the application.

I’m positive the name of the role was in reference to the massively popular video game Wolfenstein 3D; in which God Mode allowed you to walk through walls and maintain 100% health.

On occasion we would like something similar to unrestricted access in APEX without pressing a button combination; or at least provide some functionality on development which should not be available on other environments. When I’ve seen this before it’s usually nothing more than enhanced JavaScript debugging rather than enabling a powerful database process.

I’ve seen manual configurations such as granting roles, setting a data parameter or similar. But I really like the idea of automatic environment detection rather a manual configuration. I’ve seen URL detection before and this hasn’t worked out very well when the application is deployed behind proxies.

My method is based on an APEX feature which is directly responsible for the presence or absence of page components and therefore perfect for this example – Build Options.

A build option is simply a flag which controls what page components should be rendered when a page is displayed. Explorer make heavy use of this feature to control work in progress whilst releasing patches. However Build Options also have another handy setting called ‘Default on Export’.

I’m going to create a Build Option called ‘Development Mode’ (It was difficult; but I’m going to resist calling it ‘God Mode’ for the rest of this blog) which I want to enable for my application but disable on export. It’s that simple – now any component associated with it will run in my environment but not on any other.

Let’s try this – I’ve got a 3 page application; page 10, page 20 and page 30 (if this looks strange – then be aware this is the new 5.2 page numbering system when using the Blueprints) with page 30 being a kind of Developer Only debug page.

I have page 30 (and its menu entry) controlled by the “Development Mode” Build Option so it only appears on my development application; it’s excluded when I export which I preconfigured earlier, so I don’t really have to think about removal of this page too much.

With Developer Mode Enabled

Developer Mode Disabled

Simple stuff, you might think – but I also talked about JavaScript debugging earlier. What I’d like to happen is for part of my JavaScript to output some debugging when Development Mode is activated and have it deactivated when the build option is disabled. The problem is that the status of my Build Option cannot be accessed at run time through JavaScript (without introducing APEX Call-backs); so I use a little workaround.

On my Page Zero (hooray! Page Zero is still Page 0 in APEX 5.2), I create a hidden item called P0_DEVELOPMENT_MODE and apply my Build Option to it; and then my JavaScript only needs to detect the presence of that item.

function logMessage(pMessage)
{
 if ( $("#P0_DEVELOPMENT_MODE").length > 0 )
 {
 apex.debug.setLevel(apex.debug.LOG_LEVEL.INFO) 
 apex.debug.info(pMessage);
 }
}

logMessage('Development Mode On');

The above is a simple example; although if you go down this route be security aware of what can and cannot be enabled by a hacker – always place conditions, authorizations and build options on any processes or dynamic actions which interface with the database. More on APEX security here here and here.

 

 

Author: Matt Mulvaney

Job Title: Senior Oracle APEX Development Consultant

Bio: Matt is an experienced APEX solution designer having designed numerous complex systems using a broad range of Oracle Technologies. Building on his previous experience of Oracle Forms & PL/SQL, he is entirely focused on providing functionally rich APEX solutions. Matt promotes APEX as a software platform and openly shares best practises, techniques & approaches. Matt has a passion for excellence and enjoys producing high quality software solutions which provide a real business benefit.