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 | apex.message.clearErrors(); |

Success Message
1 | apex.message.clearErrors(); |

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).