Search This Blog

Showing posts with label HOW DO I Implement the "APEX Util" Button in ORACLE APEX. Show all posts
Showing posts with label HOW DO I Implement the "APEX Util" Button in ORACLE APEX. Show all posts

Sunday, July 13, 2025

HOW DO I Implement the "APEX Util" Button in ORACLE APEX

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

  1. 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

  2. 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

  3. Add a Confirmation or Feedback Message

    • Under Messages, create a success notification like:

      apex_application.g_print_success_message := 'Utility process completed.';
      
  4. 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

  1. Set the Button Action to Defined by Dynamic Action.

  2. 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”

A screenshot of a computer

Description automatically generated

  • Create a Dynamic Action

  • On the true Branch

A black and grey striped background

Description automatically generated


A black rectangular object with white text

Description automatically generated


A computer screen shot of a black bar

Description automatically generated



  • Create a second True Branch

A black screen with white text

Description automatically generated


A screenshot of a computer program

Description automatically generated

Via Submit Button

A screenshot of a computer

AI-generated content may be incorrect.


Via APEX Submit

A black rectangular object with a black stripe

Description automatically generated


A screenshot of a computer

Description automatically generated

Via Dynamic SQL

  • Create a Dynamic Action

A screenshot of a computer

Description automatically generated

  • In the true branch

A black screen with white text

Description automatically generated


A screenshot of a computer

Description automatically generated


  • In the Processing tab

A screenshot of a computer

AI-generated content may be incorrect.

  • With the following values

A black and grey striped background

Description automatically generated


A screenshot of a computer

Description automatically generated


A black and white text

Description automatically generated


A black and grey striped background

Description automatically generated


Via Dynamic JavaScript

  • At the page level

A screenshot of a computer

Description automatically generated


A screenshot of a computer

Description automatically generated


A screenshot of a computer

Description automatically generated


  • Create a dynamic action

A screenshot of a computer

Description automatically generated


  • In the True branch

A black rectangular object with white text

Description automatically generated


A black and grey background

Description automatically generated with medium confidence


A black and white text

Description automatically generated with medium confidence



Via App Util

Viewing the session values

At the bottom of your page select Session > View Session variables

A screenshot of a computer

Description automatically generated


In this example the session variables are EMPTY, but had we had any data, it would display under Item Values.

A screenshot of a computer

AI-generated content may be incorrect.

After the session is cleared

A screenshot of a computer

Description automatically generated



 

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.

 

How Do I Make a Faceted Search Map Page in Oracle APEX

Combining faceted search with a map region in Oracle APEX enables users to filter data visually and spatially at the same time. This design ...