Message Class

Contains validation errors that occur when the user saves the page that uses a standard controller.

ApexPages

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.

In a custom controller or controller extension, you can instantiate a Message in one of these ways:

  • 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:

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

To specify the severity of the message, use the ApexPages.Severity enum values. The following are the valid values:

  • CONFIRM

  • ERROR

  • FATAL

  • INFO

  • WARNING

All enums have access to standard methods, such as name and value.

The following are constructors for Message.

Creates a new instance of the ApexPages.Message class using the specified message severity and summary.

public Message(ApexPages.Severity severity, String summary)

  • severity: Type: ApexPages.Severity The severity of a Visualforce message.
  • summary: Type: String The summary Visualforce message.

Creates a new instance of the ApexPages.Message class using the specified message severity, summary, and message detail.

public Message(ApexPages.Severity severity, String summary, String detail)

  • severity: Type: ApexPages.Severity The severity of a Visualforce message.
  • summary: Type: String The summary Visualforce message.
  • detail: Type: String The detailed Visualforce message.

Creates a new instance of the ApexPages.Message class using the specified severity, summary, detail, and component ID.

public Message(ApexPages.Severity severity, String summary, String detail, String id)

  • severity: Type: ApexPages.Severity The severity of a Visualforce message.
  • summary: Type: String The summary Visualforce message.
  • detail: Type: String The detailed Visualforce message.
  • id: Type: String The ID of the Visualforce component to associate with the message, for example, a form field with an error.

The following are methods for Message. All are instance methods.

  • getComponentLabel()

    Returns the label of the associated inputField component. If no label is defined, this method returns null.

  • getDetail()

    Returns the value of the detail parameter used to create the message. If no detail String was specified, this method returns null.

  • getSeverity()

    Returns the severity enum used to create the message.

  • getSummary()

    Returns the summary String used to create the message.

Returns the label of the associated inputField component. If no label is defined, this method returns null.

public String getComponentLabel()

Type: String

Returns the value of the detail parameter used to create the message. If no detail String was specified, this method returns null.

public String getDetail()

Type: String

Returns the severity enum used to create the message.

public ApexPages.Severity getSeverity()

Type: ApexPages.Severity

Returns the summary String used to create the message.

public String getSummary()

Type: String