Message Class
Namespace
ApexPages
Usage
When using a standard controller, all validation errors, both custom and standard, that occur when the user saves the page are automatically added to the page error collections. If an inputField component is bound to the field with an error, the message is added to the component’s error collection. All messages are added to the page’s error collection. For more information, see Validation Rules and Standard Controllers in the Visualforce Developer's Guide.
If your application uses a custom controller or extension, you must use the message class for collecting errors.
Instantiation
In a custom controller or controller extension, you can instantiate a Message in one of these ways:
-
1ApexPages.Message myMsg = new ApexPages.Message(ApexPages.severity, summary);where ApexPages.severity is the enum that determines how severe a message is, and summary is the String used to summarize the message. For example:
1ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL, 'my error msg'); -
1ApexPages.Message myMsg = new ApexPages.Message(ApexPages.severity, summary, detail);where ApexPages. severity is the enum that determines how severe a message is, summary is the String used to summarize the message, and detail is the String used to provide more detailed information about the error.
- CONFIRM
- ERROR
- FATAL
- INFO
- WARNING
All enums have access to standard methods, such as name and value.