What Are Application Processes
Application processes are PL/SQL blocks that run at specific points during every page request in your APEX application. Unlike page processes which are tied to a specific page, application processes execute globally across all pages. They are configured in Shared Components and are essential for setting up session-wide state, enforcing global business rules, and running code that needs to execute on every request.
Process Points
APEX provides several process points that determine when your application process runs:
On New Session (Before Header): Runs once when a new session is created. Ideal for loading user preferences, setting application items based on user roles, or initializing session-scoped data:
-- Load user preferences on session start
BEGIN
SELECT default_language, theme_preference, items_per_page
INTO :G_LANGUAGE, :G_THEME, :G_PAGE_SIZE
FROM user_preferences
WHERE username = :APP_USER;
EXCEPTION
WHEN NO_DATA_FOUND THEN
:G_LANGUAGE := 'EN';
:G_THEME := 'LIGHT';
:G_PAGE_SIZE := 25;
END;
Before Header: Runs before the page header is rendered on every page request. Use this for computations that need to be current on every page, such as unread notification counts or system alert checks.
After Submit (Before Computation): Runs after any page is submitted but before page computations execute. Useful for global input sanitization or audit logging of all page submissions.
On Demand (AJAX Callback): Does not run automatically. Instead, it creates a named PL/SQL entry point that can be called from JavaScript via AJAX. This is the mechanism behind custom AJAX callbacks in APEX:
-- Application Process: GET_EMPLOYEE_COUNT (On Demand)
DECLARE
l_count NUMBER;
BEGIN
SELECT COUNT(*)
INTO l_count
FROM employees
WHERE department_id = APEX_APPLICATION.G_X01;
HTP.P(l_count);
END;
-- JavaScript call:
apex.server.process("GET_EMPLOYEE_COUNT", {x01: deptId}, {
success: function(data) {
apex.item("P10_EMP_COUNT").setValue(data);
}
});
Conditions and Sequence
Each application process can have a Server-Side Condition that controls whether it executes. Use conditions to skip expensive processing on pages that do not need it. The Sequence number controls the order of execution when multiple processes share the same process point. Keep sequences well-spaced (10, 20, 30) to allow inserting new processes between existing ones without renumbering.
Performance Considerations
Remember that Before Header application processes run on every single page view. Keep them lightweight. If a process involves expensive queries, consider whether the result can be cached in an application item that is only refreshed when the data changes, rather than recalculating on every page load.