I've developed a custom comments object as a child of Case to support inline images for back and forth conversation between customers and support.

The last piece is to post these comments as feed items in the case console. I've seen documentation on posting inline images into feed items (I really don't understand how to implement this: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/connectapi_examples_post_feed_element_richtext_inlineimage.htm) How can I use this and is it possible to do so with multiple images and text?

My current code creates feed items but throws an error when images are included in the body of the feed item.


System.DmlException: 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]

Code causing the error:

// iterate through comments and create a comment feed item on the associated case 
    List <FeedItem> newCommentFeedItems = new List<FeedItem>();    
    for (Case_Comments__c comments : commentsList) {
        string cbody = comments.comment__c;
        cbody = cbody.replace('<br>', '<p>&nbsp;</p>');
        FeedItem fi = new FeedItem (parentId = comments.case__c,
                                   body = cbody, 
                                   title = 'Case Comment', 
                                   isRichText = true


comments.comment__c will sometimes contain rich text and inline images

  • can you post specific code snippet or area where this issue is occuring which could help you to nail down the issue – Santanu Boral May 12 '17 at 3:13
  • I've trimmed down my code sample and isolated the field that contains rich text images which is used for the body of the feed item to be inserted – jdallas May 12 '17 at 3:26

Your Answer

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

Browse other questions tagged or ask your own question.