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 the user whose comment is mark as best comment

AnudeepAnudeep (Salesforce Developers) 
Hi Shubham, 

The Status picklist field of FeedComment object has a Select as Best option. You can send email to the user based on this value

Here is a sample code
 
trigger sendemail on FeedComment(after insert) {

for(FeedComment F: trigger.new){
if(f.Status=='Select as Best') {       

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);
}
}
}

If you find this information helpful, please mark this answer as Best. It may help others in the community

Regards, 
Anudeep

 
Shubham Bansal 45Shubham Bansal 45
Hi Anudeep I try to reproduce this but in my case the status is published not Select as best for the comment which are mark as best comment/answer.