The APEX_UTIL
package is a powerful collection of utility functions provided by Oracle APEX that allows you to control session state, send emails, set preferences, log activity, and more. When you tie an “APEX Util” button to a process that uses this package, you can perform advanced backend tasks with a single click. This is useful in scenarios where you need to clear session state, retrieve user info, generate hashes, or log activity without writing large custom procedures. In this blog post, you'll learn how to create a button that runs an APEX_UTIL
process in Oracle APEX.
How to Implement the APEX Util Button in Oracle APEX
-
Create the Button
-
Open your page in Page Designer
-
Under your desired region, click + and add a Button
-
Set the Name (e.g.,
BTN_APEX_UTIL
) and Label (e.g.,Run Utility
) -
Set Action to Submit Page
-
-
Add a PL/SQL Process to Use APEX_UTIL
-
Go to the Processing section
-
Click + Create and select Process → PL/SQL Code
-
Name the process (e.g.,
RUN_APEX_UTIL
) -
Under PL/SQL Code, use a utility from the package, for example:
apex_util.set_session_state('P1_STATUS', 'Reset'); apex_util.clear_page_cache(p_page => :APP_PAGE_ID); apex_util.set_preference(p_preference => 'LAST_USED', p_value => sysdate);
-
Under Server-Side Condition, set:
-
When Button Pressed =
BTN_APEX_UTIL
-
-
-
Add a Confirmation or Feedback Message
-
Under Messages, create a success notification like:
apex_application.g_print_success_message := 'Utility process completed.';
-
-
Optional: Add Branching
Create a branch to redirect users after the button action, or remain on the same page.
The APEX Util button retrieves and displays the session state values stored using apex_util.get_session_state().
Implementation Steps
Set the Button Action to Defined by Dynamic Action.
Create a Dynamic Action with the following attributes:
Event: Click
Action: Execute PL/SQL Code
PL/SQL Code:
DECLARE
v_fname VARCHAR2(100);
v_lname VARCHAR2(100);
BEGIN
v_fname := apex_util.get_session_state('P1_FNAME');
v_lname := apex_util.get_session_state('P1_LNAME');
apex_debug.info('Stored First Name: ' || v_fname);
apex_debug.info('Stored Last Name: ' || v_lname);
END;
This logs the stored values in the APEX debug console for troubleshooting and validation.
This tutorial demonstrated different ways to interact with text fields and buttons in Oracle APEX. The buttons use various techniques, including session state management, page submission, dynamic SQL execution, JavaScript manipulation, and APEX utilities.
Each method serves a specific purpose:
Clear Session: Clears values from session state.
Submit: Submits the page.
APEX Submit: Stores values in session state before submission.
Dynamic SQL: Executes SQL dynamically.
Dynamic JS: Modifies text fields with JavaScript.
APEX Util: Retrieves stored session values for debugging.
By combining these methods, you can create highly interactive and dynamic APEX applications.
EXAMPLE:
In this application we have two text fields and 6 buttons:
Text fields
FName
LName
Buttons
Clear Session
Submit
Apex Submit
Dynamic SQl
Dynamic JS
Apex Util
ClearSessions Button
Create button named “Clear Session”
Create a Dynamic Action
On the true Branch
Create a second True Branch
Via Submit Button
Via APEX Submit
Via Dynamic SQL
Create a Dynamic Action
In the true branch
In the Processing tab
With the following values
Via Dynamic JavaScript
At the page level
Create a dynamic action
In the True branch
Via App Util
Viewing the session values
At the bottom of your page select Session > View Session variables
In this example the session variables are EMPTY, but had we had any data, it would display under Item Values.
After the session is cleared
Best Practices for APEX Util Buttons
-
Use specific, named buttons tied to exact utilities (e.g.,
BTN_CLEAR_CACHE
,BTN_SET_PREFERENCE
) -
Always validate input before processing utility functions
-
Combine with session-state checks to avoid redundant execution
-
Use success messages or logs to confirm results for the user
-
Avoid exposing sensitive utilities to all users—use authorization schemes if needed
Group related utility actions into a single PL/SQL block for efficiency
Oracle APEX Documentation Links
Conclusion
The "APEX Util" button in Oracle APEX allows you to take advantage of powerful backend utilities with minimal code. Whether clearing session cache, setting preferences, or controlling page behavior, APEX_UTIL
functions can streamline many tasks. When attached to a submit button and wrapped in a well-structured process, these utilities become a valuable tool for maintaining, optimizing, and controlling your application behavior with ease.