When a user uploads images in RichTextArea field salesforce creates this kind of link and ContentReference
is maintained by Salesforce internally, which is not accessible by an user using the refid
.
<img src="https://c.{instance}.content.force.com/servlet/rtaImage?eid=a0yxxxxx&feoid=00Nxxxx&refid=0EMxxxxx" alt="Inline images 1" width="478" height="347"></img>
As per my understanding, you want to upload the files and want to share those files to the external customers so they can access the file without login to Salesforce.
Here, files uploaded to the Document folder or adding files to the attachment will not serve the purpose.
Best option is using Content Deliveries, refer Set Up Content Deliveries
A content delivery allows you to easily convert documents such as Microsoft® PowerPoint and Word files into an optimized web-based version for easy online viewing. Once you create your delivery, you can send its encrypted URL to any recipient, such as leads, customers, partners, and colleagues, and then track how often the content is viewed or downloaded. Content deliveries are available in Salesforce Classic only.
Look into leveraging ContentDistribution object.
Represents information about sharing a document externally.
- Content deliveries must be enabled to query content deliveries.
- Users (including users with the “View All Data” permission) can query only the files that they have access to. If the file is managed by a Content Library, the user must have “Deliver Content” enabled in the library permission definition and be a member of the library. If the file isn’t managed by a Content Library, the user must have the “Enable Creation of Content Deliveries for Salesforce Files” permission.
- Users can query the DistributionPublicUrl and Password fields only if they are the file owner, if the file is shared with them, or if the RelatedRecordId specifies a record that the users can access.
- If the shared document is deleted, the delete cascades to any associated ContentDistribution. The ContentDistribution is still queryable by using the QueryAll verb.
- If the shared document is archived, the only fields that users can edit are ExpiryDate and PreferencesExpires.
- Customer Portal users can’t access this object.
- Chatter Free users can’t access this object.
And use this property for shareable URL.
DistributionPublicUrl
- URL of the link to the shared document.
ContentDownloadUrl
- The link for downloading the file. This field is available in API version 40.0 and later.
For more information, refer ContentDistribution
Usage:
Use this object to create, update, delete, or query information about a document shared externally via a link or via Salesforce CRM Content delivery.
The ContentDistribution object supports triggers before and after these operations: insert, update, delete. It supports triggers after undelete.
How ContentDocument and ContentDistribution could be used for your usecase
When you upload a file, it will create a ContentVersion and ContentDocument record.

SOQL
SELECT Id, ContentDocumentId, ContentLocation,Title,PathOnClient
from ContentVersion
WHERE Title = 'Account Address fields'
Take the ContentDocumentId and run this SOQL on ContentDistribution
.
SELECT Id, ContentDownloadUrl, DistributionPublicUrl
FROM ContentDistribution
WHERE ContentDocumentId = '06990000003Wmx4AAC'
LIMIT 1
Now DistributionPublicUrl
will look like this, which you will share to unauthorized users:
https://{instance}/sfc/p/90000000JwQN/a/90000000Xd2U/oRLwnrP_bdzITLmLDmzxl.wG7zwDeYh6KBG.nZL0fW4
And ContentDownloadUrl
will look like this:
https://{instance}/sfc/dist/version/download/?oid=00D90000000JwQN&ids=06890000003b64Z&d=%2Fa%2F90000000Xd2Z%2FN7cGoPHEJsptTkEhg5It2kvvgXlHFK6V0ZBjs675PeA&asPdf=false
If you really want to show the image in the RichtextArea use ContentDownloadUrl
as image source
<img alt="myImage" src="https://{instance}/sfc/servlet.shepherd/version/download/06890000003b64Z?asPdf=false&operationContext=CHATTER">
</img>
RichTextArea will be displayed like this:
