ApexPages Class

Use ApexPages to add and check for messages associated with the current page, as well as to reference the current page.

Namespace

System

Usage

In addition, ApexPages is used as a namespace for the PageReference Class and the Message Class.

ApexPages Methods

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

addMessage(message)

Add a message to the current page context.

Signature

public Void addMessage(ApexPages.Message message)

Parameters

message
Type: ApexPages.Message

Return Value

Type: Void

addMessages(exceptionThrown)

Adds a list of messages to the current page context based on a thrown exception.

Signature

public Void addMessages(Exception exceptionThrown)

Parameters

exceptionThrown
Type: Exception

Return Value

Type: Void

currentPage()

Returns the current page's PageReference.

Signature

public System.PageReference currentPage()

Return Value

Type: System.PageReference

Example

This code segment returns the id parameter of the current page.

public MyController() {
    account = [
        SELECT Id, Name, Site 
        FROM Account 
        WHERE Id =
            :ApexPages.currentPage().
             getParameters().
             get('id')
    ];
}

getMessages()

Returns a list of the messages associated with the current context.

Signature

public ApexPages.Message[] getMessages()

Return Value

Type: ApexPages.Message[]

hasMessages()

Returns true if there are messages associated with the current context, false otherwise.

Signature

public Boolean hasMessages()

Return Value

Type: Boolean

hasMessages(severity)

Returns true if messages of the specified severity exist, false otherwise.

Signature

public Boolean hasMessages(ApexPages.Severity severity)

Parameters

sev
Type: ApexPages.Severity

Return Value

Type: Boolean