4

An image in a rich text field is a link to 'something' in content and looks something like:

<img src="https://c.{instance}.content.force.com/servlet/rtaImage?eid=a0yxxxxx&amp;feoid=00Nxxxx&amp;refid=0EMxxxxx" alt="Inline images 1" width="478" height="347"></img>

Where

  • eid is the object id
  • feoid is the field id
  • refid is a ContentReference id

I'm trying to programatically add an inline image by uploading an image somewhere and creating this URL, but I can't work out how to get the ContentReference Id. I'm assuming it's related to ContentDocument/ContentVersion, but the ContentReference table isn't queryable.

i.e. try running SELECT Id FROM ContentReference LIMIT 1 and you'll get an error stating entity type ContentReference does not support query

The main thing I'm try to do is store a large inline image and make it visible to unauthenticated people.
i.e. if I email them the content of a rich text field, I want them to see the image inline, which works with an externally available URL that points directly to the image, not an intermediate page.

I can't use Attachments or the standard ContentDocument, and I'm hoping to avoid using old school Documents

4
  • 1
    Out of curiosity, why not use Documents? I've always found them very useful for storing publicly accessible images.
    – martin
    Jul 6, 2017 at 2:55
  • what is the use of richtextarea, is that only to store this image only? Jul 6, 2017 at 3:31
  • @martin It's more a preference than anything, we're probably going to have to use Documents, but as a programmer I wanted to solve the problem :)
    – Nick C
    Jul 6, 2017 at 7:16
  • @SantanuBoral No, it will contain html markup with formatted text and 0 to many inline images.
    – Nick C
    Jul 6, 2017 at 7:17

2 Answers 2

5

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&amp;feoid=00Nxxxx&amp;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.

ContentVersion

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&amp;operationContext=CHATTER">
</img>

RichTextArea will be displayed like this:

RTA

6
  • Hi @santanu, thanks for taking the time for such a detailed response. One of the problems with DistributionPublicUrl is it's a url you can provide to an unauthenticated user where they can then download a file, but it won't work as an inline image, and my understanding of ContentDownloadUrl is that it's only available for logged in users. The key thing here is that the images need to be available inline, not as a separate download process.
    – Nick C
    Jul 13, 2017 at 2:21
  • did you try this thing the way I have suggested? ContentDownloadUrl which salesforce maintains and it can be used in inline image without downloading. I have done the poc at my DE before answering Jul 13, 2017 at 2:25
  • I thought I did, but re-trying it and it seems to work the way I want. Damnit. I've already given the bounty because I thought I'd have to use Documents.
    – Nick C
    Jul 13, 2017 at 4:19
  • I've implemented using the ContentDownloadUrl and it works quite well. ContentDownloadUrl is only available in API version 40.0 and above.
    – Nick C
    Aug 1, 2017 at 2:51
  • so now you can consider my answer is worth 100 points Aug 1, 2017 at 3:37
1
+100

I'd say go with Documents for this.

Very often when there are similarly named features in Salesforce, the old name represents the legacy feature and the new name represents the new and improved feature. Look at Portals vs Communities or Customizable Forecasts vs Collaborative Forecasts, etc.

With Files, Salesforce CRM Content, Salesforce Knowledge, Documents, and Attachments though, there isn't the progression in functionality where one is replacing the other. They are all still relevant and are each intended for different purposes.

From Differences Between Files, Salesforce CRM Content, Salesforce Knowledge, Documents, and Attachments:

enter image description here

1
  • So long as the inline images are below the 5MB document limit, Documents is really the best approach.
    – Nick C
    Jul 13, 2017 at 2:23

You must log in to answer this question.

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