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.
{% asset_img apex-error-message.png %}
The following demos show how to create custom error and success messages in JavaScript.
Error Messages
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
}
]);
{% asset_img apex-custom-error-message.png %}
Success Message
apex.message.clearErrors();
apex.message.showPageSuccess( "It works!" );
{% asset_img apex-custom-success-message.png %}
Wrap up
For more examples and full documentation read the apex.message
documentation.
The {% post_link how-to-save-page-data-but-show-errors-in-apex 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).