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
Charlotte HoldenCharlotte Holden 

Assistance with Email Alert for the FeedComment Trigger

Hi, I am not a Developer and do not know how to write Apex Code, so I am looking for some help, as to how I adapt the below existing code for the FeedComment Trigger so we automatically send an email alert to the case owner when a new FeedComment record is created.

trigger FeedComment_UpdateCaseStatus on FeedComment(after insert, after update){
    
    List<Case> CasesToUpdate = new List<case>();
    List<id> UserList = new List<ID>();
    List<Id> FeedItemList = new List<id>();
    String RecordTypeId = String.valueof([SELECT ID FROM Profile WHERE Name = 'Symatrix Community Plus User'].Id);

    for(FeedComment fc: Trigger.New) {
        feedItemList.add(fc.FeedItemId);
        UserList.add(fc.InsertedById);
    }

    Map<Id, FeedItem> FeedMap = new Map<id, FeedItem>([select id,InsertedById,Visibility from feedItem where Id IN :FeedItemList]);
    Map<Id, User> UserMap = new Map<Id, User>([select id, ProfileId, usertype, name from user where ID IN :UserList]);
    
    for(FeedComment fc: Trigger.New){
        if (FeedMap != null && FeedMap.containsKey(fc.feedItemId) && fc.ParentId.getSObjectType() == Case.SObjectType) {
            case cs = new case();
            cs.id = fc.ParentId;
            if (UserInfo.getProfileId() == RecordTypeId && String.valueof(fc.ParentId).substring(0,3) == '500' && cs.status != 'Open') {
                cs.status = 'Open';
            }
            cs.Last_Chatter_Feed_Timestamp__c = date.today();
            CasesToUpdate.add(cs);
        }
    }
    if (CasesToUpdate != null && CasesToUpdate.size() > 0) {
        update CasesToUpdate;
    }
}
AnkaiahAnkaiah (Salesforce Developers) 
Hi Charlotte,

You can turn on email from Chatter for all users by going to Setup>Build>Customise>Chatter>Email Settings and then tick the Allow Emails and/or Allow Email Replies.

Once enabled this setting, case owner will get the notification of feed comments.

If this helps, Please mark it as best answer.

Thanks!!
Charlotte HoldenCharlotte Holden
Hi Ankaiah, thank you for the suggestion. The problem is this doesn't work if someone comments on their own post, which happens more regularly than you think. We also can't force our customers to always use @mentioning, so there is no guarantee we see that update. Hence wanting to force an email notification to the case owner whenever the customer makes Feed Comment update.