Unveiling Oracle APEX’s apex.message: A JavaScript Powerhouse for User-Friendly Apps


Imagine this: it’s 2 a.m., and I’m hunched over my laptop, coffee long gone cold, wrestling with a stubborn Oracle APEX application. The client’s deadline is looming, and the app is almost perfect—except for one thing. The user experience feels clunky. Error messages are popping up in boring, default dialogs, success notifications vanish too quickly (or not at all), and the accessibility for screen-reader users? Let’s just say it’s nonexistent. I’m tearing my hair out, muttering, “There’s got to be a better way to handle messages!”
That’s when I stumbled upon the apex.message JavaScript API in Oracle APEX. It was like finding a hidden treasure chest in a dark cave. This module promised to transform my app’s messaging from chaotic to polished, accessible, and user-friendly. But, like any good adventure, it came with challenges: cryptic documentation, unfamiliar JavaScript quirks, and the pressure to make it work now. Spoiler alert: I survived, and apex.message became my secret weapon. In this blog post, I’m spilling all the details on what apex.message is, why it’s a game-changer, and how you can wield its powers in your APEX apps—complete with real-world examples and a step-by-step guide. Buckle up, because this is going to be a fun ride!
1. What is apex.message and Why Should You Care?
The apex.message module is a collection of JavaScript functions in Oracle APEX designed to manage and display messages in your application’s user interface (UI). These messages can range from alerts and confirmations to success notifications, error messages, or even specialized messages for users relying on assistive technologies like screen readers.
Why It Matters
Enhanced User Experience: apex.message lets you craft clean, professional messages that guide users seamlessly, whether they’re submitting a form or encountering an error.
Behavioral Control: You can steer user actions, like confirming before deleting a record, with intuitive dialogs.
Accessibility: Functions like apex.message.ariaAlertMessage ensure your app is inclusive, delivering messages audibly for screen-reader users.
Flexibility: Customize the look and behavior of messages to match your app’s theme or branding.
Where Is It Used?
In APEX web pages, such as validating forms or displaying feedback.
Within Dynamic Actions to create interactive messaging.
To handle errors or success messages after operations like saving or deleting data.
In custom plugins or themes requiring advanced messaging capabilities.
2. Core apex.message Functions and Their Real-World Uses
Let’s dive into the key apex.message functions, exploring what they do and how they shine in practical scenarios. I’ll provide simple, relatable examples for each, grounded in real-world use cases. These functions are detailed in the Oracle APEX documentation , but I’ll break them down to show how they work in the wild.
2.1. apex.message.alert
What It Does: Displays an alert dialog with an OK button. It’s non-blocking (meaning subsequent code runs without waiting for the dialog to close) and uses the jQuery UI Dialog.
Where It’s Used: When you want to inform users about a completed action or a minor error without requiring further input.
Real-World Example: Picture a form where users enter employee details. After successfully saving, you want to show a message saying, “Employee saved successfully!”
apex.message.alert("Employee saved successfully!", function() {
// This callback runs when the user clicks OK
console.log("User closed the message");
}, {
title: "Success Message", // Dialog title
style: "success", // Message style (success, information, warning, danger)
okLabel: "OK" // Text for the OK button
});
Where to Use It: In a Dynamic Action triggered after a Save Process on a “Save” button.
How to Use It: Add this code to the “Execute JavaScript Code” section of a Dynamic Action.
2.2. apex.message.confirm
What It Does: Shows a confirmation dialog with OK and Cancel buttons. It’s also non-blocking, letting you handle the user’s choice (OK or Cancel) via a callback.
Where It’s Used: When you need to ensure the user really wants to perform a sensitive action, like deleting a record.
Real-World Example: Imagine a list of employees, and the user wants to delete one. You want to confirm their intent before proceeding.
apex.message.confirm("Are you sure you want to delete this employee?", function(okPressed) {
if (okPressed) {
// If the user clicks OK
apex.submit({ request: "DELETE_EMPLOYEE" }); // Send delete request to server
} else {
// If the user clicks Cancel
console.log("User canceled the deletion");
}
}, {
title: "Delete Warning",
style: "danger",
confirmLabel: "Yes, Delete",
cancelLabel: "No"
});
Where to Use It: On a “Delete” button tied to a Dynamic Action.
How to Use It: Place this code in the “Execute JavaScript Code” section of a Dynamic Action.
2.3. apex.message.showErrors
What It Does: Displays error messages, either at the page level or inline with specific form fields.
Where It’s Used: To inform users about form validation issues, like a missing required field.
Real-World Example: Suppose a user is filling out a form with employee name and email. If the name is empty, you want to show an error.
// Clear previous errors
apex.message.clearErrors();
// Define errors
var errors = [
{
type: "error",
location: ["page", "inline"], // Show both on page and next to field
pageItem: "P1_ENAME", // Field for employee name
message: "Employee name is required!",
unsafe: false // Message is safe, no special formatting needed
},
{
type: "error",
location: ["page"], // Page-level only
message: "An error occurred in the form!",
unsafe: false
}
];
// Display errors
apex.message.showErrors(errors);
Where to Use It: In a Dynamic Action triggered after form validation.
How to Use It: Add this code to a Dynamic Action’s “Execute JavaScript Code” section or a server-side process returning errors.
2.4. apex.message.hidePageSuccess
What It Does: Hides the page’s success message (e.g., the default message shown after a successful process).
Where It’s Used: When you want to control the visibility of success messages, like hiding them after a few seconds.
Real-World Example: After saving a form, a success message appears, but you want it to disappear automatically after 3 seconds.
setTimeout(function() { apex.message.hidePageSuccess(); }, 3000); // Hides after 3 seconds
Where to Use It: In a Dynamic Action triggered after a success message is shown.
How to Use It: Add this code to the “Execute JavaScript Code” section.
2.5. apex.message.ariaAlertMessage
What It Does: Sends a message to assistive technologies (e.g., screen readers) without visual changes. The message is announced audibly.
Where It’s Used: To ensure users with visual impairments are informed of dynamic page changes.
Real-World Example: Suppose you have a table updated via AJAX. You want to notify screen-reader users that the table has refreshed.
apex.message.ariaAlertMessage("Employee table successfully updated.");
Where to Use It: After an AJAX operation that updates page content.
How to Use It: Include this in a Dynamic Action or JavaScript code triggered after the update.
3. How to Use apex.message in Your APEX App
Now that you know what these functions do, let’s walk through how to integrate them into your project.
Step 1: Adding JavaScript Code
In a Dynamic Action:
In Page Designer, create a new Dynamic Action (e.g., on a button click).
Add an Action of type “Execute JavaScript Code.”
Paste the relevant code (e.g., apex.message.alert) into the code section.
In a JavaScript File:
Create a JavaScript file with your code.
Upload it to Shared Components > Static Application Files.
Load the file in your page or application (via Page Properties > JavaScript > File URLs).
Step 2: Testing and Debugging
Use your browser’s Developer Tools (F12) to check the console for errors or confirm that your code is running.
Ensure the jQuery UI Dialog is loaded, as it’s a prerequisite for alert and confirm.
Step 3: Customizing with Themes
If you’re a theme developer, use apex.message.setThemeHooks to customize message behavior (e.g., add animations or change styles).
Example: Add a custom CSS class to success messages:
apex.message.setThemeHooks({
beforeShow: function(pMsgType, pElement) {
if (pMsgType === apex.message.TYPE.SUCCESS) {
pElement.addClass("animate-success");
}
}
});
4. A Complete Scenario: Combining Multiple Functions
Let’s tie it all together with a real-world scenario. Imagine a form where users enter employee details (name and email). You want to:
Show errors if the form is invalid.
Confirm before deleting an employee.
Display a success message after saving, then hide it after 3 seconds.
Announce updates for screen-reader users.
JavaScript Code (in a Dynamic Action):
// Validate form
function validateForm() {
var errors = [];
if (!apex.item("P1_ENAME").getValue()) {
errors.push({
type: "error",
location: ["page", "inline"],
pageItem: "P1_ENAME",
message: "Employee name is required!",
unsafe: false
});
}
if (errors.length > 0) {
apex.message.clearErrors();
apex.message.showErrors(errors);
return false;
}
return true;
}
// Save button
$("#save_button").click(function() {
if (validateForm()) {
apex.submit({ request: "SAVE_EMPLOYEE" });
apex.message.ariaAlertMessage("Employee form saved.");
apex.message.alert("Employee saved successfully!", function() {
setTimeout(function() {
apex.message.hidePageSuccess();
}, 3000);
}, { style: "success", okLabel: "OK" });
}
});
// Delete button
$("#delete_button").click(function() {
apex.message.confirm("Are you sure you want to delete this employee?", function(okPressed) {
if (okPressed) {
apex.submit({ request: "DELETE_EMPLOYEE" });
apex.message.ariaAlertMessage("Employee deleted.");
}
}, { style: "danger", confirmLabel: "Yes", cancelLabel: "No" });
});
Explanation:
The validateForm function checks if the name field is empty and shows errors if needed.
The Save button submits the form if valid, shows a success message, and hides it after 3 seconds.
The Delete button prompts for confirmation and submits a delete request if confirmed.
ARIA messages ensure accessibility for screen-reader users.
5. Best Practices and Tips
Leverage Callbacks: Since alert and confirm are non-blocking, put dependent code in their callbacks.
Prioritize Accessibility: Always use ariaAlertMessage or ariaMessage for screen-reader users.
Manage Errors: Clear old errors with apex.message.clearErrors before showing new ones.
Test Themes: If using a custom theme, verify message rendering with setThemeHooks.
Debug Effectively: Use apex.debug.log to troubleshoot callback execution or other issues.
Wrapping Up
My 2 a.m. debugging saga taught me that apex.message is more than just a JavaScript API—it’s a lifeline for creating polished, accessible, and user-friendly Oracle APEX apps. From alerts and confirmations to error handling and ARIA messages, this module has everything you need to elevate your app’s messaging game. The examples and tips above should give you a solid foundation to start experimenting in your own projects.
Got a specific apex.message challenge or want to dive deeper into a particular function? Drop a comment below, and let’s geek out together! 😄 Happy coding, and may your APEX adventures be bug-free!
Subscribe to my newsletter
Read articles from Mahdi Ahmadi directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Mahdi Ahmadi
Mahdi Ahmadi
Founder & CEO at Artabit | Oracle APEX Expert | Building Innovative HR Solutions | UAE & Iran