2

Is it possible to send push notification in Salesforce1 app without a chatter post?

AFAIK a push notification is sent after a chatter is posted.

Thanks in advance.

EDIT: A use case is ....

When an activity record is created, a push notification should be sent to a mobile user. There should be no chatter on the record.

2
  • Push notification can be sent when someone receives approval requests as well. Not sure what your are looking for. If you can post your use case, it helps in thinking work arounds. – Anurag Aug 29 '16 at 1:58
  • Let me edit the question to add a use case. – MnZ Aug 29 '16 at 2:04
2

You can use a trigger to send push notification when activity record is created. After insert trigger can be created to send push notifications.

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);

}

}

Please refer the following link.

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

3
  • This looks like for mobile SDK .Does it work for SF1 app ? – Mohith Shrivastava Aug 29 '16 at 4:27
  • This works for SF1 too – Anurag Aug 29 '16 at 13:38
  • @AnuragA I tried to call an app in place of Test_App, it didn't work. It couldnt recognize that connected app – MnZ Aug 30 '16 at 9:03

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.