In a long text field you have the ability to paste images. When an image is pasted it isn't saved into a standard object like Attachment where it can be queried to get the body of the image file. I need to be able to get the body and name of this pasted image using an external call outside of SFDC so that I can put them on an external 3rd party system. This is not the same as trying to get the body of an image that was uploaded in the rich text editor as this is a long text field.

An example of the pasted image I wish to get is similar to this.


The approach I would like to take is to connect to SFDC via my external code and then be able to download the file at the above URL. Does anyone have any suggestions on an approach to accomplish this?

1 Answer 1


You'll have to do this using two API calls.

First, you'll need to query the rich text field and parse the refid=0EM... for however many images are in the field: .../services/data/v51.0/sobjects/<<Object>>/<<Record Id>>?fields=Rich_Text__c

Your rich text field value should look something like this (line breaks added):

<p>Hang in there!</p>
<p><img src="https://blah-blah--c.documentforce.com/servlet/rtaImage?eid=0062F00000Af5Kc&amp;feoid=00N2F00000DAi7f&amp;refid=0EM2F000000DZtN" alt="image.png"></img></p>

Second, query each ContentReferenceId using the following endpoint: .../services/data/v51.0/sobjects/<<Object>>/<<Record Id>>/richTextImageFields/Rich_Text__c/0EM...

You'll need to handle the GET request binary data when saving to your 3rd party system.

See the Salesforce REST API documentation, sObject Rich Text Retrieve

  • I mistakenly said it was a rich text field, but it is a long text field. While your answer was correct for a rich text field I need to be able to get the image from a long text field instead.
    – Tad
    Apr 9, 2021 at 21:43
  • I figured out a way to get the inline image from a long text field. Using a trigger I copied the value from the long text field into a new rich text field. During the copy I replace the feoid id with the feoid of the rich text field and the. I I sed the approach gale-force-wizard indicted to get the image data.
    – Tad
    Apr 10, 2021 at 2:08
  • @Tad How you wound up with images in long text area fields is beyond me. Glad you got it working. Apr 12, 2021 at 12:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .