Activity Forums Salesforce® Discussions Salesforce Apex Code to Post a Chatter Post

  • Ratan Paul

    Member
    October 6, 2016 at 10:49 am

    So you need to use chatter api.

    check this https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/connectapi_examples_post_feed_element_mention.htm

    ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
    ConnectApi.MentionSegmentInput mentionSegmentInput = new ConnectApi.MentionSegmentInput();
    ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput();
    ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput();

    messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();

    mentionSegmentInput.id = '005RR000000Dme9';
    messageBodyInput.messageSegments.add(mentionSegmentInput);

    textSegmentInput.text = 'Could you take a look?';
    messageBodyInput.messageSegments.add(textSegmentInput);

    feedItemInput.body = messageBodyInput;
    feedItemInput.feedElementType = ConnectApi.FeedElementType.FeedItem;
    feedItemInput.subjectId = '0F9RR0000004CPw';

    ConnectApi.FeedElement feedElement = ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), feedItemInput, null);

  • Ajit

    Member
    October 7, 2016 at 9:29 am

    Hi Ratan,

    It worked for me but I found one way also by using Rest call out in my apex code

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos