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
Karthik jKarthik j 

How to send chatter notification to single person in apex

Hi
I have a requirement like, whenever a user creates a task and it is closed by another user, then I have to send a chatter notification to the user who created the task, I have written this code.

public static void postFeed(Set<Id>caseIdset){
        List<FeedItem> postlist = new List<FeedItem>();
        for(Id caseId:caseIdset){
        FeedItem post=new FeedItem();
        post.ParentId = caseId;
        post.Body ='task is closed';
        postlist.add(post);
        }
        if(postlist.size()>0){
            insert postlist;
        }

This one is sending chatter notifications to everyone when a task is closed, how I can make it send notifications to the user who created it.
Please help me in this.