Thursday 11 May 2017

Query Case related Chatter Feed & Post Chatter Related Record

Query

SELECT Id, Type, Body FROM caseFeed WHERE ParentId = '5004E0000035Ggw'

Code to post Chatter Feed

if (trgCtx.isAfter && trgCtx.isUpdate){
            for(sobject so : trgCtx.oldList){
            Case csOld = (Case)so;
                if(csOld.Is_Violation_Action__c == true && csOld.Milestone_message__c != null){
                    ConnectApi.FeedItemInput feedItemInput_1 = new ConnectApi.FeedItemInput();
                    ConnectApi.MentionSegmentInput mentionSegmentInput_1 = new ConnectApi.MentionSegmentInput();
                    ConnectApi.MessageBodyInput messageBodyInput_1 = new ConnectApi.MessageBodyInput();
                    ConnectApi.TextSegmentInput textSegmentInput_1 = new ConnectApi.TextSegmentInput();
                    messageBodyInput_1.messageSegments = new List<ConnectApi.MessageSegmentInput>();
                   
                    textSegmentInput_1.text = csOld.Milestone_message__c;
                    System.debug('****textSegmentInput_1.text******* ' + textSegmentInput_1.text);
                    System.debug('****csOld.Milestone_message__c******* ' + csOld.Milestone_message__c);
                    mentionSegmentInput_1.id = csOld.Ownerid;
                    System.debug('****mentionSegmentInput_1.id******* ' + mentionSegmentInput_1.id);
                    System.debug('****csOld.Ownerid******* ' + csOld.Ownerid);
                    messageBodyInput_1.messageSegments.add(mentionSegmentInput_1);                                
                    messageBodyInput_1.messageSegments.add(textSegmentInput_1);
                    feedItemInput_1.body = messageBodyInput_1;
                    feedItemInput_1.feedElementType = ConnectApi.FeedElementType.FeedItem;
                    feedItemInput_1.subjectId = csOld.id;
                    System.debug('*****feedItemInput_1.subjectId ****** ' + csOld.id);
             
                    if(!Test.isRunningTest()){
                        ConnectApi.FeedElement feedElement = ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), feedItemInput_1);
                   }
                 }
            }
       }

No comments:

Post a Comment

Batch Apex

1. What are transaction limits in apex? Total number of SOQL queries issued1 - 100 Total number of records retrieved by SOQL queries - 50...