3

Using ConnectApi Reference: http://www.salesforce.com/us/developer/docs/apexcode/Content/connectAPI_outputs.htm#capi_entityLinkSeg_output

I want to create from apex code a chatter post on a record, a post that will include a link to a site enter image description here

exactly i want to create ,from apex,the following: enter image description here

Do you know if there is some function to accomplish that?

Thanks in advantage for any advice.

3

With the help of Mohith i got the solution: Usign ConnectApi.LinkSegmentinput isn´t giving the desired solution: Code(working with test account hardcoded):

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


    ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput();
    textSegment.text = 'text ';
    messageInput.messageSegments.add(textSegment);

    ConnectApi.LinkSegmentinput linksegment = new ConnectApi.LinkSegmentinput();
            linksegment.url = 'http://testme.com';
   messageInput.messageSegments.add(linksegment);



    ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();
    input.body = messageInput;
       ConnectApi.ChatterFeeds.postFeedItem(null, ConnectApi.FeedType.Record, '001g000000FrBWt', input, null);

this is the result: enter image description here

The desidered solution for me is usign ConnectApi.LinkAttachmentInput:

ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
    feedItemInput.body = new ConnectApi.MessageBodyInput();

    // add the text segment
    ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput();
    feedItemInput.body.messageSegments = new List<ConnectApi.MessageSegmentInput>();
    textSegment.text = 'postText';
    feedItemInput.body.messageSegments.add(textSegment);

    // add the attachment
    ConnectApi.LinkAttachmentInput linkIn = new ConnectApi.LinkAttachmentInput();
    linkIn.urlName = 'urlName';
    linkIn.url = 'url';
    feedItemInput.attachment = linkIn;


       ConnectApi.ChatterFeeds.postFeedItem(null, ConnectApi.FeedType.Record, '001g000000FrBWt',feedItemInput, null);
| improve this answer | |
1
//Adding a Link post

FeedItem post = new FeedItem();
post.ParentId = oId; //eg. Opportunity id, custom object id..
post.Body = 'Enter post text here';
post.LinkUrl = 'http://www.someurl.com';
insert post;

If you are not using community,the following should work using simple apex .

Other way to use will be using connect API

  ConnectApi.FeedItemInput input=new ConnectApi.FeedItemInput();
  ConnectApi.MessageBodyInput  body1 = new ConnectApi.MessageBodyInput();  
body1.messageSegments = new List<ConnectApi.MessageSegmentInput>();
ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput();
textSegment.text ='message';
body1.messageSegments.add(textSegment);

 // linksegment
    ConnectApi.LinkSegmentInput linksegment = new ConnectApi.LinkSegmentInput();
    linksegment.url = 'http://testme.com';
    body1.messageSegments.add(linksegment);
    input.body=body1 ;

  ConnectApi.ChatterFeeds.postFeedItem(Network.getNetworkId(),ConnectApi.FeedType.News,'me',input,null);
| improve this answer | |
  • Thanks Mohith, i need to do it with Connect Api. Do you know if is it feasible? – Enry Apr 11 '14 at 10:21
  • Ok hold on ..its feasible ..I am updating the answer – Mohith Shrivastava Apr 11 '14 at 10:23
  • Added the code .Let me know if issues – Mohith Shrivastava Apr 11 '14 at 11:12
  • Thanks again. i get a compiler error about : Incompatible element type ConnectApi.LinkSegment segmentList.add(linksegment); for collection of ConnectApi.MessageSegmentInput. – Enry Apr 11 '14 at 12:03
  • no luck :( Save error: Illegal assignment from LIST<ConnectApi.MessageSegment> to ConnectApi.MessageBodyInput – Enry Apr 11 '14 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.