---
schema_version: "1"
id: d893d4ff137710969ac0035cb157460049c263f60200acf629f40270cc136cde
title: ApexPages Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_methods_system_apexpages.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_apexpages.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: d35a45f629b6f4b1cb37b6092184d074639ce05cd6afeeb56d872918016837fd
description: Use ApexPages to add and check for messages associated with the current page, as well as to reference the current page.Add a message to the current page context.Adds a list of messages to the current page context based on a thrown exception.Returns the current page's PageReference.Returns a list of the messages associated with the current context.Returns true if there are messages associated with the current context, false otherwise.Returns true if messages of the specified severity exist, false otherwise.
---
# 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](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_System.htm "The System namespace provides classes and methods for core Apex functionality.")

## Usage

In addition, ApexPages is used as a namespace for the [PageReference Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_system_pagereference.htm "A PageReference is a reference to an instantiation of a page. Among other attributes, PageReferences consist of a URL and a set of query parameter names and values.") and the [Message Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_pages_message.htm#apex_pages_message "Contains validation errors that occur when the user saves the page that uses a standard controller.").

## ApexPages Methods

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

- **[addMessage(message)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_apexpages.htm#apex_System_ApexPages_addMessage)**  
    Add a message to the current page context.
- **[addMessages(exceptionThrown)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_apexpages.htm#apex_System_ApexPages_addMessages)**  
    Adds a list of messages to the current page context based on a thrown exception.
- **[currentPage()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_apexpages.htm#apex_System_ApexPages_currentPage)**  
    Returns the current page's PageReference.
- **[getMessages()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_apexpages.htm#apex_System_ApexPages_getMessages)**  
    Returns a list of the messages associated with the current context.
- **[hasMessages()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_apexpages.htm#apex_System_ApexPages_hasMessages)**  
    Returns true if there are messages associated with the current context, false otherwise.
- **[hasMessages(severity)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_apexpages.htm#apex_System_ApexPages_hasMessages_2)**  
    Returns true if messages of the specified severity exist, false otherwise.

### addMessage(message)

Add a message to the current page context.

#### Signature

public Void addMessage(ApexPages.Message message)

#### Parameters

- **message**: Type: [ApexPages.Message](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_pages_message.htm#apex_pages_message "Contains validation errors that occur when the user saves the page that uses a standard controller.")

#### 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](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_exception_methods.htm "An exception denotes an error that disrupts the normal flow of code execution. You can use Apex built-in exceptions or create custom exceptions. All exceptions have common methods.")

#### Return Value

Type: Void

### currentPage()

Returns the current page's PageReference.

#### Signature

public System.PageReference currentPage()

#### Return Value

Type: [System.PageReference](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_system_pagereference.htm "A PageReference is a reference to an instantiation of a page. Among other attributes, PageReferences consist of a URL and a set of query parameter names and values.")

#### 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')
        WITH USER\_MODE\];
}

### getMessages()

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

#### Signature

public ApexPages.Message\[\] getMessages()

#### Return Value

Type: [ApexPages.Message](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_pages_message.htm#apex_pages_message "Contains validation errors that occur when the user saves the page that uses a standard controller.")\[\]

### hasMessages()

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

#### Signature

public Boolean hasMessages()

#### Return Value

Type: [Boolean](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_boolean.htm#apex_methods_system_boolean "Contains methods for the Boolean primitive data type.")

### 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](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_pages_message.htm#apexpages_severity_enum)

#### Return Value

Type: [Boolean](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_boolean.htm#apex_methods_system_boolean "Contains methods for the Boolean primitive data type.")