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 

FeedComment Apex Trigger to Update Field/Status depending on Profile Used to make Update

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
VamsiVamsi
Hey,

replace the below code with the below new version hope it helps ..!!
 
updates.add(new Case(
                    Id = fc.ParentId,
                    Status = 'Open'
                    ));

*********************new version************

case cs = new case();
cs.id = fc.ParentId;
cs.Last_Chatter_Feed_Timestamp__c = date.today();
if(UserInfo.getProfileId == 'ABC')
{
  cs.Status = 'Open';
}
 updates.add(cs);
        
Charlotte HoldenCharlotte Holden
Hi, Thank you for the quick update. I'm getting an error: Error: Compile Error: Variable does not exist: getProfileId at line 17 column 25
Line 17 is :     
  • if(UserInfo.getProfileId == '00e3L000000M0wu')
Do I need to add something further up in the code too please?
Charlotte HoldenCharlotte Holden
I'm also getting the below error when trying to import the original code which does work into PROD, and not sure why:
"Your organization's code coverage is 73%. You need at least 75% coverage to complete this deployment. Also, the following triggers have 0% code coverage. Each trigger must have at least 1% code coverage."