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
Shubham Bansal 45Shubham Bansal 45 

I want to send custom mail to the user whose answer in community is selected as best answer.

when an answer is selected as best the id of that answer is stored in feeditem field but  i want to send an immediate mail when answer is selected as best.

i have tried using after update trigger on feeditem but its no use.

can any one help.
AnudeepAnudeep (Salesforce Developers) 
Hi Shubham, 

Can you try checking if the BestCommentId is populated and then sending an email based on that? 
 
trigger sendemail on FeedItem(after insert) {

for(FeedItem F: trigger.new){
if(f.BestCommentId!='') {       

user u=[select firstname,lastname from user where id=:f.InsertedById limit 1];
                                 
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
message.toAddresses = new String[] { 'Saurabh.dua@hotmail.com' };
message.optOutPolicy = 'FILTER';
message.subject = 'New Case Feed';
message.HTMLBody = '<b>Message Body:</b>' +f.body +
                    '<b>Created by:</b>' + u.firstname+' '+u.lastname;
Messaging.SingleEmailMessage[] messages =   new List<Messaging.SingleEmailMessage> {message};
Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
}
}
}

Thanks, 
Anudeep
 
Shubham Bansal 45Shubham Bansal 45
I understand this approach but the problem is when someone mark a comment as the best answer the bestcommentid field of feeditem store the id of that comment but how should I know that the value is get stored, I tried after update trigger to achieve this on feed item but when best comment id is stored after an update is also not triggered, therefore I am not able to find any trace to find when I should trigger the apex code. My functionality is to send mail at the time the best comment is selected.
Shubham Bansal 45Shubham Bansal 45
I have the search you on LinkedIn for getting a clear clue but unfortunately not found you.