Why Confirmation Dialogs Matter
Destructive operations like deleting records, approving financial transactions, or submitting irreversible workflows should always prompt the user for confirmation. Oracle APEX does not include a built in declarative “confirm before submit” action, but building one with Dynamic Actions is straightforward and the pattern is reusable across your entire application.
The Basic Pattern
The simplest approach uses a Dynamic Action on the button click event with a JavaScript action that displays a confirmation dialog:
Create a Dynamic Action on your Delete button with the event set to Click. Set the action to Execute JavaScript Code with the following:
apex.message.confirm("Are you sure you want to delete this record?", function(okPressed) {
if (okPressed) {
apex.submit({request: 'DELETE', showWait: true});
}
});
Set the “Fire on Initialization” property to No. Under the Dynamic Action’s Advanced section, make sure “Event Scope” is set to Static. This prevents the button’s default submit behavior from firing before the dialog appears.
Making It Reusable
Rather than duplicating this pattern on every page, create a JavaScript function in your application’s global static file:
// File: /static/js/app_common.js
function confirmAndSubmit(pMessage, pRequest, pOptions) {
var defaults = {showWait: true};
var opts = Object.assign({}, defaults, pOptions || {});
apex.message.confirm(pMessage, function(okPressed) {
if (okPressed) {
apex.submit({request: pRequest, showWait: opts.showWait});
}
});
}
// Usage in any Dynamic Action:
// confirmAndSubmit("Delete this record permanently?", "DELETE");
// confirmAndSubmit("Submit for approval?", "APPROVE", {showWait: false});
Now every confirmation dialog in your application calls the same function, and you can change the dialog style, add logging, or switch to a custom modal by editing one file.
Enhanced Version With Item Validation
For forms where you want to validate before confirming, extend the function to check required items first:
function validateConfirmSubmit(pMessage, pRequest, pItemsToCheck) {
// Check required items first
if (pItemsToCheck && !apex.page.validate()) {
return; // Stop if validation fails
}
apex.message.confirm(pMessage, function(okPressed) {
if (okPressed) {
apex.submit({request: pRequest, showWait: true});
}
});
}
This pattern ensures the user sees validation errors before the confirmation dialog appears, which is a much better user experience than confirming and then seeing errors after the page round trip.