APEX client side error messages - apex.message.showErrors

Von Tobias Arnhold 10.25.2018
Since APEX 5.1 we have the ability to create client side messages without the requirement to use a plugin or custom code to create nice looking client side messages.

For that requirement the APEX team created the apex.message library.

This library provides the same look and feel as if you would create a message out of your Page Designer > Validation Area.



In this example I will tell you something about a more advanced way to use the client side error messages.

As the documentation says this is the default way to create a client side error message:

/* General page error message */
apex.message.showErrors([
{
type: "error",
location: "page",
message: "Page error has occurred!",
unsafe: false
}
]);
  /* Item error message */ apex.message.showErrors([
{
type: "error",
location: [ "page", "inline" ],
pageItem: "P1_ITEM",
message: "Value is required!",
unsafe: false
}
]);

Example for a page error message:




In my example I want to check more then one item. For that I created an array including all item names I wanted to check. Within a "FOR" loop I run through every item and created an error message if the value was NULL. If no error occurred I run another custom dynamic action.

apex.message.clearErrors();

var chkErr = 0;
var arr = [
   'P1_STRASSE', 
   'P1_HAUS_NR',
   'P1_PLZ', 
   'P1_ORT', 
   'P1_ITEM_XYZ'
];

for (var i in arr) {
  if ($v(arr[i]).length == 0) {
    apex.message.showErrors([
      {
        type: apex.message.TYPE.ERROR,
        location: ["inline"],
        pageItem: arr[i],
        message: "Value is required!",
        unsafe: false
      }
    ]);
    chkErr = 1;
  } 
}

if ( chkErr == 0 ) { 
  /* Custom dynamic action call when no error occurred */
  apex.event.trigger(document, 'customDA', [{customAttribute:'1'}]); 
}
You want to know more? Check out the documentation and this series of blog posts by Martin D'Souza:
https://www.talkapex.com/2018/03/custom-apex-notification-messages/
https://www.talkapex.com/2018/03/how-to-save-page-data-but-show-errors-in-apex/

Post Tags: