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
Arjun y 7Arjun y 7 

Unable to send Email Notification to users when a post is created via Apex

Hi All,

I have a requirement to send emails to the account owner whenever a post is created in their feed.

I wrote the below code to insert feeditem. If i add createdbyid field in post, i am unable to get the emails.

If i comment the createdbyid, then i am able to recieve the emails. 
FeedItem post = new FeedItem();
post.ParentId = '0F9c0000000DLT6CAO'; 
post.createdById = '005a000000BA2zjAAD';
post.Body = 'Happy Anniversary, Sean!';
insert post;
Can anyone please let me know how can i achieve this?

Thank You
Arjun
Ajay mishraAjay mishra
Hi Arjun,

createdById is used to show Who created Post. If you do not pass this Id, It will create post with the current user in salesforce.

 And If Id is passed in the field it will send the email to that user who's Id is passed in it.

check with the user Email inbox.
Arjun y 7Arjun y 7
Hi Ajay,

I passed id to the createdById field. And i didn't receive any mail from chatter.

If i don't pass id, then i am receiving email from running user.

Thanks
Arjun
Ajay mishraAjay mishra
Are using any custom code to send the email to user ??
Arjun y 7Arjun y 7
Yes. I am using the below code to insert post in chatter. When post is inserted, email will automatically generate to users from salesforce. But, t is not happening,
FeedItem post = new FeedItem();
post.ParentId = '0F9c0000000DLT6CAO'; 
post.createdById = '005a000000BA2zjAAD';// I am passing this value from Custom label
post.Body = 'Happy Anniversary, Sean!';
insert post;
Ajay mishraAjay mishra
Arjun, I mean to ask for sending email. above code is for creating FeedItem.
Rakesh51Rakesh51
Correct code you have mention is used to genereate new Feed, can you post the code of send email trigger ?


ANother question for you, where you're posting feed ? account feed or some where else ?
 
Richa Gupta 40Richa Gupta 40
Hey..could you find any resolution for this?
I am facing the same issue