Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

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

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

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.

1public MyController() {
2    account = [
3        SELECT Id, Name, Site 
4        FROM Account 
5        WHERE Id =
6            :ApexPages.currentPage().
7             getParameters().
8             get('id')
9    ];
10}

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

Return Value

Type: Boolean