0

Is it possible to send a push message from a salesforce lightning app? For instance suppose a record has been created and I want a push notification in my mobile phone. I am fairly new at this and have no idea where to start so any help would be appreciated.

3

Actually, the question is about sending push notification from a Lightning app. The provided link is for native and hybrid mobile apps (not Lightning apps or Lightning pages).

To clarify, Lightning framework by itself does NOT provide any support for push notifications. You will need to wrap your Lightning pages into a hybrid application and use an approach such as Apex triggers to generate push notifications for mobile clients.

Below is an example which shows a push notification being generated when a case is updated (pure Apex code, no Lightning)

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 connected app.  
        msg.send('Test_App', users);
    }
}
2

Yes, Yes it is.

There are two ways of doing this. First, is to use the Marketing Cloud's JB4A SDK for either Android or IOS. The second is to use the core platform's push notification features.

I suspect, since you've not mentioned the Marketing Cloud that you're wanting to use core features. Here's some documentation on how to do that:

https://developer.salesforce.com/docs/atlas.en-us.pushImplGuide.meta/pushImplGuide/pns_registration_process.htm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.