• Charlotte Holden
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
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;
    }
}
I'm hoping you clever people are able to help me please, as I do not know how to write Apex Code.

I have pulled the below from another post (which works), but need to adopt it for the following circumstances, and wondered whether someone might be able to help please:
  • For any update made, update field 'Last_Chatter_Feed_Timestamp__c' with todays date.
  • For any update made and the profile ID = ABC, flip the status to 'Open'

trigger FeedThis on FeedComment(after insert, after update){

    List<Case> updates = new List<case>();
    List<id> userList = new List<ID>();
    List<Id> feedItemList = new List<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, 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) {
            updates.add(new Case(
                    Id = fc.ParentId,
                    Status = 'Open'
                    ));
        }
        
    }
    if(updates != null && updates.size() > 0)
    update updates;
}

Many Thanks In Advance
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;
    }
}
I'm hoping you clever people are able to help me please, as I do not know how to write Apex Code.

I have pulled the below from another post (which works), but need to adopt it for the following circumstances, and wondered whether someone might be able to help please:
  • For any update made, update field 'Last_Chatter_Feed_Timestamp__c' with todays date.
  • For any update made and the profile ID = ABC, flip the status to 'Open'

trigger FeedThis on FeedComment(after insert, after update){

    List<Case> updates = new List<case>();
    List<id> userList = new List<ID>();
    List<Id> feedItemList = new List<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, 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) {
            updates.add(new Case(
                    Id = fc.ParentId,
                    Status = 'Open'
                    ));
        }
        
    }
    if(updates != null && updates.size() > 0)
    update updates;
}

Many Thanks In Advance