---
schema_version: "1"
id: 287feca81ea146fd437c08d353f315b1a2bded25bf0d06ff676fba47b8552061
title: NotificationAction Interface
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_interface_reports_NotificationAction.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_reports_NotificationAction.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: a86b6a55febb6c45d8442de2ab6914ef86cb7a65243d2a8b31eb49596bf6e7b5
description: Implement this interface to trigger a custom Apex class when the conditions for a report notification are met.Executes the custom Apex action specified in the context parameter of the context object, NotificationActionContext. The object contains information about the report instance and the conditions that must be met for a notification to be triggered. The method executes whenever the specified conditions are met.
---
# NotificationAction Interface

Implement this interface to trigger a custom Apex class when the conditions for a report notification are met.

## Namespace

[Reports](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_Reports.htm "The Reports namespace provides classes for accessing the same data as is available in the Salesforce Reports and Dashboards REST API.")

## Usage

Report notifications for reports that users have subscribed to can trigger a custom Apex class, which must implement the Reports.NotificationAction interface. The execute method in this interface receives a NotificationActionContext object as a parameter, which contains information about the report instance and the conditions that must be met for a notification to be triggered.

- **[NotificationAction Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_reports_NotificationAction.htm#apex_reports_NotificationAction_methods)**
- **[NotificationAction Example Implementation](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_reports_NotificationAction.htm#apex_interface_reports_NotificationAction_Example)**

## NotificationAction Methods

The following are methods for NotificationAction.

- **[execute(context)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_reports_NotificationAction.htm#apex_reports_NotificationAction_execute)**  
    Executes the custom Apex action specified in the context parameter of the context object, NotificationActionContext. The object contains information about the report instance and the conditions that must be met for a notification to be triggered. The method executes whenever the specified conditions are met.

### execute(context)

Executes the custom Apex action specified in the context parameter of the context object, NotificationActionContext. The object contains information about the report instance and the conditions that must be met for a notification to be triggered. The method executes whenever the specified conditions are met.

#### Signature

public void execute(Reports.NotificationActionContext context)

#### Parameters

- **context**:
    
    Type: [Reports.NotificationActionContext](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_reports_NotificationActionContext.htm#apex_class_reports_NotificationActionContext "Contains information about the report instance and condition threshold for a report notification.")

#### Return Value

Type: Void

## NotificationAction Example Implementation

This is an example implementation of the Reports.NotificationAction interface.

public with sharing class AlertOwners implements Reports.NotificationAction {

    public void execute(Reports.NotificationActionContext context) {
        Reports.ReportResults results = context.getReportInstance().getReportResults();
        for(Reports.GroupingValue g: results.getGroupingsDown().getGroupings()) {
            FeedItem t = new FeedItem();
            t.ParentId = (Id)g.getValue();
            t.Body = 'This record needs attention. Please view the report.';
            t.Title = 'Needs Attention: '\+ results.getReportMetadata().getName();
            t.LinkUrl = '/' + results.getReportMetadata().getId();
            insert as user t;
        }
    }
}