Salesforce Service Console feeds gives a holistic view of all the actions happening on cases which your agents can refer for quick summary of all that is happening on that case. It is also useful when the cases are transferred to some other support agent.
There is some limitations in the feed we see on service console which might require you to customize Since not all feed actions are in detail. For example if you see an email feed , it contains whole body of the email , where as a feed on a new case related object created will contain only the record name or auto-number by default. Though you can add a compact layout for the object which will allow you to add more fields in the feed but here we have a limit of 255 character on each field.
Example : Suppose you add these fields in case compact layout then these will appear in the feed where each field e.g Subject can contain maximum of 255 characters
- Case Number
- Subject
- Status
These standard feeds are not writable in trigger hence can't be modified if you want to add more details (more than 255 characters) . In this case an alternate option is to add the feed comment to same feed post where you can add up to 10,000 characters in feed comment.
The way standard feed post is added in Salesforce is asynchronous hence , if you will try to access the standard feed in After trigger of the object then the following query will return no rows.
SELECT Id, ParentId ,Type, Body FROM <Your Object>__Feed WHERE ParentId ='<Your Object>'
ORDER BY CreatedDate DESC
The only way to access the Feed object is to run this query in a future call. Here is the sample code for adding feed comment with details to system generated feed.
<Your Object> Trigger Code
trigger afterinsert_<Your Object> on <Your Object> (after insert) {
Set<Id> ObjectIds = new Set<Id>();
for(<Your Object> obj: Trigger.New){
ObjectIds .add(obj.Id);
}
if(ObjectIds !=null && !ObjectIds .isEmpty() ){
<Your Object>_TriggerHelperCalss.Add_FeedItemComment(ObjectIds );
}
}
<Your Object> TriggerHelper Class Code
public class <Your Object>_TriggerHelper{
@future
public static void Add_FeedItemComment(Set<Id> ObjectIdSet){
Map<Id, <Your Object>> feedMap = new Map<Id, <Your Object>>([Select id ,Body__c
from <Your Object>
where id IN :ObjectIdSet]);
String communityId = null;
for(<Your Object>__Feed feed : [SELECT Id, ParentId , Type, Body
FROM <Your Object>__Feed
WHERE ParentId IN :ObjectIdSet ORDER BY CreatedDate DESC] ){
String targetUserOrGroupOrRecordId = feed.Id;
if(feedMap!=null && feedMap.containsKey(feed.ParentId)){
ConnectApi.CommentInput input = addDetailComment(feedMap.get(feed.ParentId));
ConnectApi.Comment comment = ConnectApi.ChatterFeeds.postCommentToFeedElement(communityId, targetUserOrGroupOrRecordId, input , null );
}
}
}
private static ConnectApi.CommentInput addDetailComment(<Your Object> object){
ConnectApi.CommentInput input = new ConnectApi.CommentInput();
ConnectApi.MessageBodyInput messageInput = new ConnectApi.MessageBodyInput();
messageInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
ConnectApi.MarkupBeginSegmentInput beginSegment = new ConnectApi.MarkupBeginSegmentInput();
beginSegment.markupType = ConnectApi.MarkupType.Bold;
messageInput.messageSegments.add(beginSegment);
ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput();
textSegment.text = 'Detail Body';
messageInput.messageSegments.add(textSegment);
ConnectApi.MarkupEndSegmentInput endSegment = new ConnectApi.MarkupEndSegmentInput();
endSegment.markupType = ConnectApi.MarkupType.Bold;
messageInput.messageSegments.add(endSegment);
input.body = messageInput;
return input;
}
}
}
Comments
Post a Comment