You need to sign in to do that
Don't have an account?
Raviraj S 1
How to add image in chatter post
I want to add image in chatter post. I am trying the below example but the ContentData and ContentFileName fields are not present in FeedItem. API version 39.0. I also got similar post but I am facing the same issue.
Blob body=[Select Name, ContentType, Body From StaticResource where name='abc'].body;
FeedItem post = new FeedItem();
post.ParentId = u.id;
post.CreatedById='005E0000003XWRs';
post.Body ='Happy birthday '+u.name;
post.ContentData = body;
post.ContentFileName = 'sample.png';
insert post;
I also tried with below code, but here img tag is not working. it throws error as :- Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Referenced file id is invalid, not accessible, or does not exist: [RawBody]
FeedItem post = new FeedItem();
post.ParentId = recipientId;
post.CreatedById = loggedUser;
post.IsRichText = true;
post.Body = message+'<p> </p><img src="/img/rypple/Thanks.png">'+badgeReceived.Description;
post.RelatedRecordId = thanks.Id;
insert post;
Blob body=[Select Name, ContentType, Body From StaticResource where name='abc'].body;
FeedItem post = new FeedItem();
post.ParentId = u.id;
post.CreatedById='005E0000003XWRs';
post.Body ='Happy birthday '+u.name;
post.ContentData = body;
post.ContentFileName = 'sample.png';
insert post;
I also tried with below code, but here img tag is not working. it throws error as :- Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Referenced file id is invalid, not accessible, or does not exist: [RawBody]
FeedItem post = new FeedItem();
post.ParentId = recipientId;
post.CreatedById = loggedUser;
post.IsRichText = true;
post.Body = message+'<p> </p><img src="/img/rypple/Thanks.png">'+badgeReceived.Description;
post.RelatedRecordId = thanks.Id;
insert post;