+ Start a Discussion
Shruthi NarsiShruthi Narsi 

Apex Code to get custom notification and post to chatter

I need to post to chatter if the opportunity and lead has 3 tasks pending.Can anyone modiy the below code accordingly

public class MyBellNotification { public static void notifyCurrentUser(String message) { Http h = new Http(); HttpRequest req = new HttpRequest(); req.setEndpoint(Url.getOrgDomainUrl().toExternalForm() + '/services/data/v46.0/actions/standard/customNotificationAction'); req.setMethod('POST'); req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId()); req.setHeader('Content-Type', 'application/json'); CustomNotificationActionInput input = new CustomNotificationActionInput(); input.customNotifTypeId = '0ML0b000000KyjGGAS'; input.recipientIds = new List<String>{UserInfo.getUserId()}; input.title = 'Test Data Operation Completed'; input.body = message; input.targetId = '0ML0b000000KyjGGAS'; CustomNotificationAction action = new CustomNotificationAction(); action.inputs = new List<CustomNotificationActionInput>{input}; req.setBody(JSON.serialize(action)); HttpResponse res = h.send(req); System.debug(res.getBody()); } public class CustomNotificationAction { public List<CustomNotificationActionInput> inputs { get; set; } } public class CustomNotificationActionInput { public String customNotifTypeId { get; set; } public List<String> recipientIds { get; set; } public String title { get; set; } public String body { get; set; } public String targetId { get; set; } } }
AbhishekAbhishek (Salesforce Developers) 
Hi Shruthi,

You can try the suggestions as mentioned in the below blogs,

https://salesforce.stackexchange.com/questions/196136/salesforce-lightning-experience-bell-notifications

https://salesforce.stackexchange.com/questions/256989/bell-notifications-via-apex

https://andyinthecloud.com/2019/06/30/getting-your-users-attention-with-custom-notifications/

https://salesforce.stackexchange.com/questions/265572/show-custom-bell-notifications-in-salesforce-lightning

I hope the above helps you.