I am planning to implement this trigger on the FeedComment object, as this object is not available for use via Lightning Process Builder. I'm looking to update the case when a certain type of user (based on profile) adds a comment to a feed item (e.g. someone makes a post on the chatter feed and then a reply is added subsequently).
This simple trigger appears to "do the job," but I am curious as to whether it is to best practices or there is a better more eloquent way to write this:
trigger FeedCommentTest on FeedComment (after insert)
{
for(FeedComment f : Trigger.New)
{
if(UserInfo.getProfileId() == '00e23000000DeaWAAS' && String.valueof(f.ParentId).substring(0,3) == '500' )
{
Case CaseToUpdate = [SELECT ID FROM CASE WHERE ID =: f.ParentId];
CaseToUpdate.Status = 'Customer Replied';
CaseToUpdate.Description = 'success';
Update CaseToUpdate;
}
}
}
UPDATE:
Here is my updated trigger that I will use in production:
trigger FeedComment_UpdateCaseStatus on FeedComment (after insert)
{
String RecordTypeId = String.valueof([SELECT ID FROM Profile WHERE Name = 'Customer Community Login User'].Id);
for(FeedComment f : Trigger.New)
{
if(UserInfo.getProfileId() == RecordTypeId && String.valueof(f.ParentId).substring(0,3) == '500' )
{
Case CaseToUpdate = [SELECT ID, Status FROM CASE WHERE ID =: f.ParentId];
if(CaseToUpdate.Status != 'Customer Replied')
{
CaseToUpdate.Status = 'Customer Replied';
Update CaseToUpdate;
}
}
}
}
Thanks in advance!