I'm developing a mobile app for both Android and iOS that will receive push notifications. I've followed the instructions in the Salesforce Mobile Push Notifications Implementation Guide and created a Connected App for each platform. I've configured push for each app, and I can successfully push using the 'Send Test Notification' link on each connected app's management page.

The documentation lists instructions for sending push notifications from Apex using Messaging.PushNotification; the process is slightly different for iOS and Android, and you pass the connected app's name when you send the notification.

So, if I want to send a push notification to Joe User, how do I know which type of notification to send? The sample code only shows pushing an iOS notification. He could have iOS or Android. When the mobile app registers, it registers for a specific connected app; the platform knows which device(s) the user has. When you send a test push notification, you can see the most recent push registrations for that connected app and even search by name - but that object (which I suspect is named Mobile Push Service Device) does not appear to be queryable.

I suppose I could have each mobile app register something on the user record or similar, but I feel like I'd be duplicating the push registration functionality, only without all the smart bits that track when a push registration is no longer valid. Should I just try to send both types of notification to every User? Seems like a waste of resources.

1 Answer 1


When you send push notifications from Apex, you don't need to know which devices users have registered. You need to create a list of user ids for the users you want to send notification to. Then create Messaging.PushNotification object, set a payload for this object and use its "send" method to send push notifications to the list of users. Here is an example:


If you have 2 applications that you want to send the same notifications to (1 for Android and 1 for iOS), you will call "send" method 2 times for the same list of user ids but with different application name. You can also create different Messaging.PushNotification objects for iOS and Android notifications and use different payload if you need.

  • 1
    This is the approach I ended up using (send one notification of each type to same list of users). The nice thing is, per the docs, only notifications that succeed count against the limit. Commented Jun 17, 2015 at 13:00
  • Yes, only those notifications that were actually sent count against the limit. So if your list of user ids includes users that don't have devices registered, they will not be counted against the limit.
    – Aleksandra
    Commented Jun 18, 2015 at 13:52
  • Hi what kind of mobile app did you use? Is it hybrid remote/local? Commented Aug 22, 2015 at 15:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .