---
schema_version: "1"
id: fdf658186424c2be5336da54075afb016fa0c9383c3000fa19c6ffc528a80ebb
title: PushNotification Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_classes_push_notification.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_push_notification.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: e3af074d1b68c02cf3eac92c81e90904149163df85da341677011372d171b5f1
description: PushNotification is used to configure push notifications and send them from an Apex trigger.
---
# PushNotification Class

PushNotification is used to configure push notifications and send them from an Apex trigger.

## Namespace

[Messaging](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_Messaging.htm "The Messaging namespace provides classes and methods for Salesforce notifications and email functionality.")

## Example

This sample Apex trigger sends push notifications to the external client app named Test\_App, which corresponds to a mobile app on iOS mobile clients. The trigger fires after cases have been updated and sends the push notification to two users: the case owner and the user who last modified the case.

trigger caseAlert on Case (after update) {    
    
    for(Case cs : Trigger.New)  
    {
        // Instantiating a notification
        Messaging.PushNotification msg = 
            new Messaging.PushNotification();

        // Assembling the necessary payload parameters for Apple.
        // Apple params are: 
        // (<alert text>,<alert sound>,<badge count>,
        // <free-form data>)
        // This example doesn't use badge count or free-form data.
        // The number of notifications that haven't been acted
        // upon by the intended recipient is best calculated
        // at the time of the push. This timing helps
        // ensure accuracy across multiple target devices.
        Map<String, Object\> payload = 
            Messaging.PushNotificationPayload.apple(
                'Case ' + cs.CaseNumber + ' status changed to: ' 
                + cs.Status, '', null, null);

        // Adding the assembled payload to the notification
        msg.setPayload(payload);

        // Getting recipient users
        String userId1 = cs.OwnerId;
        String userId2 = cs.LastModifiedById;

        // Adding recipient users to list
        Set<String\> users = new Set<String\>();
        users.add(userId1);
        users.add(userId2);                       

        // Sending the notification to the specified app and users.
        // Here we specify the API name of the external client app.  
        msg.send('Test\_App', users);
    }
}

- **[PushNotification Constructors](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_Messaging_PushNotification_constructors.htm)**
- **[PushNotification Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_Messaging_PushNotification_methods.htm)**