• sherrywang
  • NEWBIE
  • 0 Points
  • Member since 2019


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 3
    Replies
I'm at the beginning of configuring a Trigger for Push Notifications. I don't have a the mobile app yet (being built by another team member), so I'm mainly putting it together, getting test methods running, etc.

Here's my trigger:
trigger ObjectTrigger on Object__c (after insert) {
        
    for (Object__c m : Trigger.new) {
        Messaging.PushNotification msg                  = new Messaging.PushNotification();
        Messaging.PushNotification androidMsg   = new Messaging.PushNotification();

            Map<String, Object> payload             = Messaging.PushNotificationPayload.apple('New Message: ' + m.Subject__c , '', null, null);
            Map<String, Object> androidPayload      = new Map<String, Object>();
                androidPayload.put('subject', 'New Message: ' + m.Subject__c);

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

            // Adding recipient users to list
            Set<String> users = new Set<String>();
                users.add(UserInfo.getUserId());

            // Sending the notification to the specified app and users.
            // Here we specify the API name of the connected app.  
            msg.send('Test_App', users);
            androidMsg.send('Test_App', users);
        }

    }

}
When running a test method against this, I get an error at the line: "msg.send('Test_App', users);", with the error being:
 
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, MessageTrigger: execution of AfterInsert

caused by: System.NoAccessException: Invalid connected application: Test_App

Class.Messaging.PushNotification.send: line 28, column 1
Trigger.MessageTrigger: line 22, column 1: []

I do have a Connected App setup, but it's essentially a placeholder. Is there something that I need to explicitly configure in the Connected App for the Push Notifications to not error out?
 
I want to push custom notifications to Salesforce1 not using Chatter. I found there is api can push notifications to native apps but not Salesforce1 because I don't know the api name of Salesforce1 for iOS. Can anyone help me on this? 
I want to push custom notifications to Salesforce1 not using Chatter. I found there is api can push notifications to native apps but not Salesforce1 because I don't know the api name of Salesforce1 for iOS. Can anyone help me on this?