function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sachin_KSachin_K 

Posting image and link in chatter feed through apex code

Hi

 

I am able to post a link using feeditem object and setting its type as "link post". Besides link, I need to post a image to chatter feed. It should not be like a separate file that got uploaded. 

 

Sample output : 

 

chatter page  

 

 username : some content goes here   <image> some content goes here

My link

 

<image> - an external link is used to display the image

 

Thanks.

 

Jia HuJia Hu

You may use a link to point to your image in a Feed, 

 

FeedItem fi = new FeedItem();
fi.Body = ' image link is : www.google.com !!!';
fi.ParentId = '#######';   //UserId or GroupId
insert fi;

Sachin_KSachin_K

Hi Jia,

 

Thanks for the reply.

 

But by this method we are getting the link and not the image in the chatter. What we want is to display a image (image link we have in advance)  in the chatter. Do you if this is possible?

 

Thanks,

Sachin

 

Jia HuJia Hu
So far, it is impossible I guess.

But technically it is possible. On the Chatter page, in the beginning of each feed, system uses different small pictures to distinguish different Feed's parent, such as Contact, Group, Lead,..

If they make this available for our Feed, we can do the same thing.
ChrisOctagonChrisOctagon

You can post an image in a chatter feed item using the Chatter REST API. The image can be a new binary included in your request, or you can provide the ID of existing content for your image.

Jia HuJia Hu
Hi ChrisOctagon,

Thanks for your hint.
Now, I can post through Chatter REST API. But I donot know how to include the binary into the text post.

Can you give me an example or a link?
ChrisOctagonChrisOctagon
Jia HuJia Hu
Thanks for your links very much.
But all of them are posting image as a attachment to a Feed,...
I guess it is impossible to post a image in the Body of the Feed.
ChrisOctagonChrisOctagon

I don't understand what you are looking for. It is impossible to post an image in the feed without it being an attachment to a feed item. There is no way to do that through the regular UI, so there is no API for it either.

Jia HuJia Hu
Yeah, I totally agree with you on this.

But Sachin_K is trying to find a way of posting image in the post body, and it seems you give the hope :)