Friday, September 11, 2015

@chatter Mention user

Hello everyone after the version 31 below methods are no longer available 

ConnectApi.ChatterFeeds.getFeedItemsFromFeed(null, ConnectApi.FeedType.News, userId);


So how we can do @mention now . see sample code below how to do that .


// Method that takes the list sobject as  parameter and post 


    public static void postOnChatter(List<Sobject> Items){

        List<ConnectApi.BatchInput> batchInputs = new                      List<ConnectApi.BatchInput>();
Integer MAXSIZE = 10 ;// Select Your size
        for (Sobject item : Items) {
            //  initialize the FeedItemInput
            ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();
            input.subjectId = item.Id;
            
            // initialize the body of the chatter post
            ConnectApi.MessageBodyInput body = new ConnectApi.MessageBodyInput();
            body.messageSegments = new List<ConnectApi.MessageSegmentInput>();
            
            // add the mention to the post
            ConnectApi.MentionSegmentInput mentionSegment = new ConnectApi.MentionSegmentInput();
            mentionSegment.id = item.OwnerId;
            body.messageSegments.add(mentionSegment);
            
            // add the text containing the Product Name and the tracking information
            ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput();
            textSegment.text = 'Sample Text';
            body.messageSegments.add(textSegment);
            
            input.body = body;
            ConnectApi.BatchInput batchInput = new ConnectApi.BatchInput(input);
            
            // add the FeedItemInput instances to a list
            batchInputs.add(batchInput);
            
            // postFeedElementBatch() method can process maximum of 500 feeds at a time
            // if the feeds are 500, post them and re-instantiate the list
            if(batchInputs.size() == MAXSIZE){
                ConnectApi.ChatterFeeds.postFeedElementBatch(Network.getNetworkId(), batchInputs);
                batchInputs = new List<ConnectApi.BatchInput>();
            }
        }
        // post the feeds  in the list
        if(batchInputs.size() > 0)
            ConnectApi.ChatterFeeds.postFeedElementBatch(Network.getNetworkId(), batchInputs);
    }

Tips on passing Salesforce AI Associate Certification

  🌟 Motivation to Pursue the Salesforce AI Associate Certification 🌟 The world of technology is in a state of perpetual evolution, and on...