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
Justin LonisJustin Lonis 

looking to start to create a trigger for an email notification on feed comments for cases

Hi, 

So I worked to get email notifications with a combination of schema builder, flow, process builder and workflow rules but wasn't able to do it for feed comments. 

Any help would be greatly appreciated. Or if there is a way to use my existing PB, FLOW, SB and WF let me know as well! 

Thanks!!!
JSingh9JSingh9

Hi Justin, 

I think Trigger on Feed Comment is the Only Solution. 

Try this Code

 

trigger FeedItem on FeedComment (after insert) {
   List<Messaging.SingleEmailMessage> lstMsgs = new List<Messaging.SingleEmailMessage>();
    for(FeedItem feedItem : Trigger.new){
        //Filter Feed Items related to Cases
        if(feedItem.ParentId.startsWith('500')){
            //Email Logic
            Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage();
            msg.setSubject('Subject Goes Here');
            msg.setTargetObjectId('UserId');
            msg.setHtmlBody();
            msg.setSaveAsActivity(false);
            msg.setBccAddresses(lstBccAddress); 
            lstMsgs.add(msg);
         }  
    }
    Messaging.sendEmail(lstMsgs);
}
Hope this helps

Thanks,
Jaspreet
Justin LonisJustin Lonis
This is awesome Jaspreet! Great Help! I have a few questions...I'll provide screenshots....I'm a rookie just learning my way here. 

So here is our email template now how close can this trigger get to having this stuff? Well the most important would be case number, feed comment and the url to the case:

User-added image

Second question the bbc address....do I put in the intellimail in here? Thats the BCC compliance.... (I got an error "@" when I put that in the   msg.setBccAddresses(lstBccAddress);()


User-added image


Are there any other spots where I have to put stuff in or is this trigger pretty much done. I'm curious how does the email send out/what does it look like? The email template and the merge fields are what I have experience in. Below is an example of a case feed and the response from the customer (customer profile) that would need to be sent to the case owner: 

User-added image
 
JSingh9JSingh9

Hi there,

 

you need to create a new List

List<String> bccAddress = new List<String>();

then add address

bccAddress.add('test@gmail.com');

and now add it to that code msg.setBccAddresses(lstBccAddress);

 

Please check this link for various methods supported by SingleEmailMessage Class,https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_email_outbound_single.htm

either you have to put the whole body in the setHTMLBody and then use the values from trigger to populate them or you can set Email Template as well.

 

Please let me know how it goes.

 

Thanks,
Jaspreet