A message for a specific component, such as a warning or error. If an <apex:message> or <apex:messages> component is not included in a page, most warning and error messages are only shown in the debug log.
Visualforce page:
<apex:inputField value=”{!account.NumberOfEmployees}” id=”Employee_validation”/>
<apex:message for=”Employee_validation” />
Apex Class:
ApexPages.addMessages(exception);