Quantcast
Channel: Active questions tagged chatter-feed - Salesforce Stack Exchange
Viewing all articles
Browse latest Browse all 192

create a feed stream

$
0
0

im kinda new to apex and sf i general.. i was recently tasked with fetching specific feeds that fulfill some criteria (1. addressed to context user [to Me feeds], 2. contain a mention of case object that are open).. quite alright, ive been able to retrieve these feeds using connect api methods....

but i need a way to display these retrieved feeds in a seperate window.. first idea was to make use of a vf page, but i cant see anything that helps me do that online...

and now another idea i have seen is to create a stream.. but how i do add those exact feed elements to the stream????? pls help me here.. thank you

 public class DisplayChatterController{


public DisplayChatterController(){
//  Connectapi.FeedElement newfeed;  not sure if this is necessary
}

public static void getFeeds(){
   list<Case> CaseIdlist = new list<Case>();
   CaseIdlist = [SELECT id,CaseNumber FROM Case WHERE Status = 'New' Or Status ='On Hold' or status= 'Escalated'] ;

   Connectapi.feedType fd = connectApi.feedtype.To;
   Connectapi.FeedElementPage fpp = Connectapi.ChatterFeeds.getFeedElementsfromFeed(null,fd,'me');
   Connectapi.FeedElementPage newfeedpage ;  
   Connectapi.feedelement n;
   Connectapi.FeedElement newfeed;
   list<ConnectApi.FeedElement> b = fpp.elements;//puts all feed elements in an array
   String feed;
   String comment;
   String identity;
   for(integer i =0; i<b.size();i++){
        boolean gotCaseInFeed = false;
        n = b[i]; //get the feedelement at index i
        Connectapi.CommentPage cp = Connectapi.ChatterFeeds.getCommentsForFeedElement(null, n.id);
        list<Connectapi.Comment> dComments = cp.items;//list of comments for feed n at index [i]
       /*logic
        1. loop thru the message segments and check if any instance of the message segments contain a reference to a case
        2. if none of them do, then fetch commentpage for the Feedelement and loop through 
        3. store all these feeds in some sort of container so that we can display them in a visualforce page
       */
       for (integer j =0; j<n.body.MessageSegments.size();j++){ 
            Connectapi.MessageSegment m = n.body.MessageSegments[j];//get message segments per feed     
            //condition 2.. when the feed messageSegment is an entitylink segment input
            if(m instanceof Connectapi.EntityLinkSegment){
                Connectapi.EntityLinkSegment ent = (Connectapi.EntityLinkSegment)m;
                identity = string.valueOf(ent.reference.id);//get the referenced Id
                for(Case cs: CaseIdlist){
                    if(identity == String.valueOf(cs.Id)){
                        system.debug('this feed has an entitylink with an Id of: ' + identity);
                        gotCaseInFeed = true;
                        //system.debug(n);
                        newfeed =n;//feed to be displayed
                       // newfeedpage.elements.add(newfeed);
                    }                                                                            
                }
            }
        }
            //comments should only be checked when the all of the feed items message segments does not contain the
            //reference to a case.. 
       if(gotCaseInFeed == false){
           for(integer k = 0; k < dcomments.size();k++){
               Connectapi.comment cm = dcomments[k]; //each comment in the comment array
               comment = cm.body.text;  
               for (case cs: CaseIdlist){       
                   if(comment.contains(String.valueOf(cs.CaseNumber)))
                       system.debug('this comment contains a string Value of a referenced case number: '+comment);
                        newfeed =n;//feed to be displayed
                  // newfeedpage.elements.add(newfeed);
               }
           }
       }
   }
    //  return newfeedpage.elements;
}
  }

thats my code guys.. i appreciate any form of useful advice on this thanks


Viewing all articles
Browse latest Browse all 192


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>