Apex Messages in Salesforce | Show Messages in an easy fashion

Apex Messages in Salesforce are used in displaying messages in standard visualforce pages, unless you are not using the cool frameworks like BootStrap or FlatUI, where you show error messages in a neat fashion.

Before we move on, I would like you go through Apex:Severity messages to see what type of severity can be shown on pages and how are they displayed on pages.

I designed a simple code snippet that handles all sort of apex messages on visualforce pages at one place for you, you can re-use this code at any point in any custom class and show messages in convenient way.

Ideally this is how you show error messages using Apex

Now I designed a PageHelper class that handles many things but include method that shows the message in modular way, so all you care is calling method with name and pass on message to display on page.

You can call these method by simply calling

PageUtlity.showError('No Record Found');
PageUtlity.showWarning('No Record Found');
PageUtlity.showSuccess('Record Found');
PageUtlity.showInfo('You know how to search');

Lets say, you have a page, which is plugged in to custom controller, the page has search box to search for account,if user find a matching record, we will show success and if not then we show error message, clearly this is how you add the messages login in your controller

Below is a sample message on success, you add this util class to your project and make your life easy when-ever you want to show error messages moving forward

You May Also Like

0
comments

About me

Hi. I’m Enterprise Architect (IT) at Intuitive Surgical Inc , building worlds smartest and largest surgical robots and binding business systems with cloud. I’m Founder of OyeCode. I have worked with Salesforce.com as Technical Architect (HQ) in San Francisco and designed/developed the cutting edge Salesforce Product Trailhead . I enjoy development on Salesforce, Heroku, Rails and other cloud based platform