You need to sign in to do that
Don't have an account?
Jeremy Sparrell
Push notifications on created cases
I cannot get push notifications to fire in the console when a new Case is created. It works for updated cases and create on other objects.
Hi Jeremy Sparrell,
Please see the below steps to set up push notifications in salesforce on a particular action. There are two ways which I suggest you:-
Step 1:- Please go to the setup and type Custom Notification Type and select it. Please create a new custom notification record if not created.
Create a process builder which will fire on a specific object record creation which you will select in a process builder object option and see the below images for reference:-
Step 2:- After creating a custom notification record you can also write a trigger on that particular object instead of process builder:-
*** Trigger ***
trigger PushNotificationTriggerOnCaseCreation on Case (after insert) {
if((trigger.IsAfter)&&(trigger.IsInsert)){
PushNotification.sendPushNotification();
}
}
******** Apex Code *********
public class PushNotification {
public static void sendPushNotification(){
try{
List<Case> caseRecord=new List<Case>();
caseRecord = [select Id from Case where Id=:Trigger.New limit 1];
system.debug('-------In sendCustomnotification Method------');
Messaging.CustomNotification notificationObj = new Messaging.CustomNotification();
notificationObj.setBody('New Case is created with id: '+ caseRecord[0].Id);
notificationObj.setTitle('Case Creation');
notificationObj.setSenderId(Userinfo.getUserId());
CustomNotificationType type = [SELECT Id FROM CustomNotificationType WHERE DeveloperName = 'Custom_Notifatication'];
notificationObj.setNotificationTypeId(type.id);
notificationObj.setTargetId(caseRecord[0].Id);
notificationObj.send(new Set<String> { Userinfo.getUserId() });
}
catch(Exception ex)
{
System.debug('Exception at line >>>> '+ex.getLineNumber()+'Exception >>>>>> '+ex.getMessage());
}
}
}
The output will be like:-
I hope you find the above solution helpful. If it does, please mark it as Best Answer to help others too.
Thanks and Regards,
Suraj Tripathi