Available in: Axsy Mobile for Salesforce


Sending Mobile Push Notifications from Apex

This article describes how to send push notifications to the Axsy Mobile app from Salesforce Apex code. Notifications are supported on iOS, Android and Windows. 


To send a push notification to a user across all devices they are logged in, use the sendPushNotification method in the axsy_mobile namespace. This method will create a Notification__c record, and deliver the notification via the Apple / Google / Microsoft notification services. Once the Apex governor limit is reached (typically 10 per Apex transaction) then this method will not attempt to deliver further notifications.


Method Signature

global static Notification__c sendPushNotification(

   Id recipientId,

   String title,

   String body,

   Id target,

   String type,

   Map<String, Object> userData

 )


Method Parameters

recipientId: Id of the user to send the notification to. It will be delivered to all devices the user is logged in

title: the title of the notification

body: the body of the notification

target: Id of an SObject which the notification is associated with e.g. Visit, Account. If specified, the mobile app will sync changes for this record from Salesforce when the notification is received. Optional (can be set to null)

type: sets the Notification__c.Type__c field, optional (can be set to null)

userData: additional parameters which are passed to the Apple / Google / Microsoft notification services, optional (can be set to null)

Method Returns

Either an axsy_mobile__Notification__c object which has been inserted into the database, representing the notification that has been sent, or null if the notification couldn’t be created. 


Examples

Send a basic notification:

axsy_mobile.NotificationUtils.sendPushNotification(

   UserInfo.getUserId(),

   'Test Message',

   'Hello World!',

   null,

   null,

   null

);


Send a notification associated with a Visit record, causing the mobile app to sync changes from Salesforce for this record:

axsy_mobile__Notification__c notif = axsy_mobile.NotificationUtils.sendPushNotification(
    UserInfo.getUserId(), 

'Visit Update',

'You have been assigned a new visit', 

'0Z54x000000ChfvCAC',

null, 

null

);