function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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,

I hope the above helps you.