PushNotification クラス
名前空間
例
このサンプル Apex トリガは、iOS モバイルクライアント上のモバイルアプリケーションに対応する、Test_App という名前の接続アプリケーションに転送通知を送信します。トリガは、ケースが更新された後に起動され、転送通知をケースの所有者とケースの最終変更者の 2 人のユーザに送信します。
1trigger caseAlert on Case (after update) {
2
3 for(Case cs : Trigger.New)
4 {
5 // Instantiating a notification
6 Messaging.PushNotification msg =
7 new Messaging.PushNotification();
8
9 // Assembling the necessary payload parameters for Apple.
10 // Apple params are:
11 // (<alert text>,<alert sound>,<badge count>,
12 // <free-form data>)
13 // This example doesn't use badge count or free-form data.
14 // The number of notifications that haven't been acted
15 // upon by the intended recipient is best calculated
16 // at the time of the push. This timing helps
17 // ensure accuracy across multiple target devices.
18 Map<String, Object> payload =
19 Messaging.PushNotificationPayload.apple(
20 'Case ' + cs.CaseNumber + ' status changed to: '
21 + cs.Status, '', null, null);
22
23 // Adding the assembled payload to the notification
24 msg.setPayload(payload);
25
26 // Getting recipient users
27 String userId1 = cs.OwnerId;
28 String userId2 = cs.LastModifiedById;
29
30 // Adding recipient users to list
31 Set<String> users = new Set<String>();
32 users.add(userId1);
33 users.add(userId2);
34
35 // Sending the notification to the specified app and users.
36 // Here we specify the API name of the connected app.
37 msg.send('Test_App', users);
38 }
39}