How to Disable an APEX Application During a Release

All my releases are done via scripts. In other words I don’t deploy APEX applications from the browser, rather straight from SQLcl. Since some of my releases can take a while and puts the code in an unstable state I usually disable the application for the duration of the release. This article will show how to disable an APEX application in PL/SQL.

You can manually disable an application via Shared Components > Application Definition > Availability > Status:

When setting the Status to Unavailable it will look like this for users:

Note: they’re various status options which allow you to determine how to define the status message.

Going back to releases, the overall order things occur in are:

  1. Disable APEX application
  2. Run release (DDL, DML, etc)
  3. Update APEX application (this will clear the disabled setting that was manually done in the first step.

PL/SQL code to disable an APEX application:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
declare
l_app_id apex_applications.application_id%type := 102;
begin
-- Pre APEX 18.x
-- oos_util_apex.create_session(
-- p_app_id => l_app_id,
-- p_user_name => 'RELEASE'
-- );

-- APEX 18.x +
apex_session.create_session (
p_app_id => l_app_id,
p_page_id => 1,
p_username => 'RELEASE');

apex_util.set_application_status(
p_application_id => l_app_id,
p_application_status => 'UNAVAILABLE',
p_unavailable_value => 'Updating application');

commit;
end;
/

If using a version lower than APEX 18.x you’ll need to install OOS Utils to create an APEX session in SQL.

Before running the above code you’ll need to enable the runtime API by going to Shared Components > Security Attributes > Database Session > Runtime API Usage and check Modify This Application.

Documention for apex_util.set_application_status.