+ Start a Discussion

Push Notifications: Invalid connected application

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

            // Adding recipient users to list
            Set<String> users = new Set<String>();

            // 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?
Miguel DuarteMiguel Duarte
Hi @aj2taylo2010, 

you are getting that error because on line 21 and 22 of your trigger class you have 'Test_App' and it should be the API name of your Connected App. So try switch 'Test_App' by something like 'Push_Notification_Test' (assuming that your Connected App is called Push Notification Test).

Let me know if this helps!
premkumar Rajapremkumar Raja

Question regarding this thread
What will be the name of the connected app, if I use Salesforce for Android connected app.
 I am trying to send push notification to salesforce mobile app installed in my mobile. when a case is updated a notification is sent


Reply to the thread above:

Salesforce for Android and Salesforce for iOS API names are:


you can find them from App Manager page. or query AppMenuItem table.
however, even after I switch to use the api name above, i still get the same error: Invalid connected application

Hi Sherry - it's been a while since I looked at this, but I ended up conditionally calling teh send method if it wasn't in test mode, i.e.
public static void sendGenericIosPushNotification(Set<String> pushUsers, String alertSubject) {
    Messaging.PushNotification iosMsg       = new Messaging.PushNotification();
    Map<String, Object> iosPayload          = Messaging.PushNotificationPayload.apple(alertSubject , '', null, null);
    // Adding the assembled payload to the notification

        iosMsg.send('Connected_App_Name', pushUsers);