Custom APEX Notification Messages

Ever wonder how APEX generates error messages (shown below)? Want to create your own? Starting in APEX 5.1 you can create your own error and success messages using the apex.message library.

The following demos show how to create custom error and success messages in JavaScript.

Error Messages

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
apex.message.clearErrors();

apex.message.showErrors([
{
type: apex.message.TYPE.ERROR,
location: ["page", "inline"],
pageItem: "P1_DEMO",
message: "This field is required",
unsafe: false
},
{
type: apex.message.TYPE.ERROR,
location: ["page"],
message: "Page level error",
unsafe: false
}
]);


Success Message

1
2
3
apex.message.clearErrors();

apex.message.showPageSuccess( "It works!" );


Wrap up

For more examples and full documentation read the apex.message documentation.

The next post covers how to leverage the apex_message API to simulate an error in APEX without an error happening (it will also cover why you’d want to do this).