Skip navigation
Rodrigo Mesquita

Apex APEX_ERROR API

Posted by Rodrigo Mesquita Jan 27, 2017

    When we create an apex process to execute some pl/sql code, we have the Success Message and Error message fields to input a message and give to the user an alert at the end of the process execution informing the success or failure.

     Usually there are many possibilities of error on a extensive pl/sql code, and one simple generic error alert is not so productive. It's more easier to show specific messages telling the user in which process point something went wrong.


The Apex API called APEX_ERROR helps a lot. When this procedure is executed, the an apex error message alert shows. We can use this on validations and process.

 

A simple way to use it:

 

begin


If :P1_ENAME is null then

 

APEX_ERROR.ADD_ERROR (

    p_message  => 'The employee name can´t be null',

    p_display_location => apex_error.c_inline_in_notification );

 

Elsif :P1_HIREDATE > sysdate then

 

APEX_ERROR.ADD_ERROR (

    p_message  => 'The Hiredate must be less than or equal to today',

    p_display_location => apex_error.c_inline_in_notification );

 

End IF;

 

insert into Emp(ENAME,HIREDATE) values (:P1_ENAME,:P1_HIREDATE);


end;


Submit the page and the result is:

 

 




You can show the notification on the page item too. Adding the p_page_item_name parameter the page item is highlighted on the page. The error message is displayed inline in a notification.


begin


If :P1_ENAME is null then


APEX_ERROR.ADD_ERROR (

    p_message  => 'The employee name can´t be null',

    p_display_location => apex_error.c_inline_with_field_and_notif ,

    p_page_item_name => 'P1_ENAME');


Elsif :P1_HIREDATE > sysdate then


APEX_ERROR.ADD_ERROR (

    p_message  => 'The Hiredate must be less than or equal to today',

    p_display_location => apex_error.c_inline_with_field_and_notif ,

    p_page_item_name => 'P1_HIREDATE');

Else


insert into Emp(ENAME,HIREDATE) values (:P1_ENAME,:P1_HIREDATE);


End If;

end;

 

apex error

 

 

The complete APEX_ERROR API docs, can be found on this link