[Salesforce] CustomNotification

hyunsooSong·2022년 10월 12일
0

Salesforce

목록 보기
12/13
post-thumbnail

🔔 CustomNotification


1. Full Code

  • notification.setTitle('');
  • notification.setBody('');
  • notification.setNotificationTypeId();
  • notification.setTargetId();
  • notification.send();
for (Campaign obj : listTarget) {
	Messaging.CustomNotification notification = new Messaging.CustomNotification();

	// Set the contents for the notification
	notification.setTitle('');
	notification.setBody(obj.Name);

	// Set the notification type and target
	notification.setNotificationTypeId(notificationType.Id);
	notification.setTargetId(obj.Id);

	// Actually send the notification
	try {
		notification.send(setUserId);
	} catch (Exception e) {
		System.debug('Problem sending notification: ' + e.getMessage());
	}
}

2. Get CustomNotificationType

CustomNotificationType은 Salesforce Org 내에서 만든 사용자 정의 알림을 말한다.

CustomNotificationType notificationType = [
	SELECT Id, DeveloperName
	FROM CustomNotificationType
	WHERE DeveloperName = 'Custom_Alert'
];

notification.setNotificationTypeId(notificationType.Id);

profile
🥕 개발 공부 중 🥕

0개의 댓글