Salesforceはカスタム通知を使用します
Salesforceでは、ページの右上隅にある小さなベルはプラットフォームの通知機能です。これはメッセージプッシュに似ています。イベントが発生すると、指定されたユーザーにプッシュされ、ユーザーは支払いを行うことができます。初めて使う時の注意イベントへ。
Salesforceは、カスタム通知の機能も提供します。InterfaceGUI+ Apexの少量のコードを使用して、カスタム通知をカスタマイズし、プラットフォームレベルのプッシュメッセージを実現できます。
プラットフォーム設定
まず、クイック検索ボックスの左側にある設定ページに入り、カスタム通知を入力し、クリックしてサブページに入ります。
ポップアップボックスの[新規]ボタンの右側をクリックし、名前とカスタム通知API名を入力します。これは、ApexクラスでAPIを使用するフォローアップの名前です。
サポートされているチャネルはデスクトップとモバイルです。Salesforceの両端は互換性があります。[保存]をクリックします。
Apexクラス
通知を送信するための作業クラスとして、新しいApexクラスを作成します。カスタム通知クラスはMessaging.CustomNotification
です。
Messaging.CustomNotification
属性
属性名 | の種類 | 意味 |
---|---|---|
typeId | ストリング | カスタム通知ID |
送信者 | ストリング | 送信者ID |
題名 | ストリング | 題名 |
体 | ストリング | テキスト |
targetId | ストリング | ターゲットレコードのID |
targetPageRef | ストリング | 非記録ページインデックス |
方法
send(user)
setNotificationTypeId(id)
setTitle(title)
setBody(body)
setSenderId(id)
setTargetId(id)
setTargetPageRef(pageRef)
基本的にプロパティsetter
メソッド。
コード例
public without sharing class CustomNotificationFromApex {
public static void notifyUsers(Set<String> recipientsIds, String targetId) {
// 取得自定义通知的Id
CustomNotificationType notificationType =
[SELECT Id, DeveloperName
FROM CustomNotificationType
WHERE DeveloperName='Custom_Notification'];
// 新建一个自定义通知对象
Messaging.CustomNotification notification = new Messaging.CustomNotification();
// 设置标题、正文
notification.setTitle('Apex Custom Notification');
notification.setBody('The notifications are coming from INSIDE the Apex!');
// 设置类型和目标记录Id
notification.setNotificationTypeId(notificationType.Id);
notification.setTargetId(targetId);
// 发送通知
try {
notification.send(recipientsIds);
}
catch (Exception e) {
System.debug('Problem sending notification: ' + e.getMessage());
}
}
}
targetIdを設定した後、通知プッシュをクリックすると、pageReferencesを設定しなくても、IDのレコードページに自動的にジャンプすることに注意してください。
参照リンク
より完全なドキュメントについては、公式ドキュメントを参照してください