Loading

Can't see images when accessed through Sites or Digital Experiences

Data pubblicazione: Oct 13, 2022
Descrizione

Scenario -
User has a website which connects to Salesforce.com using the Soap API (enterprise.wsdl).
User is querying for a rich text area custom field which is used to upload images.

For instance, here is a SOQL Query where Resolution__c is rich area text field used to upload images -
SELECT Resolution__c FROM myArticle WHERE ArticleNumber= '000001' AND PublishStatus='Online' AND IsLatestVersion = true AND Language='en_US'

Issue -
The above API query result is an html img element (with src) to the actual image, which resides on Salesforce internal servers.

When the user accesses this record on the portal, images do not display.
When the user logins in Salesforce and refreshes the portal page then the images appear.

Risoluzione
This is working as designed.
Attempting to use the image url from an unauthenticated browser session results in the issue.
Images in the rich text area fields are meant to be "Salesforce internally available only" by default.
There is no api that will allow to retrieve the body or actual file of an image file from a rich text area field.

Workaround :
1) Consider to switch to using a "file" field type instead of rich area text field and put your images there.
Or
Put your images in the documents object.

Both allow you to get the actual body of the document via the API query call. Read about this API query call and review the resources relating to Salesforce Knowledge

2) If you were doing this with Articles in Salesforce, articles can be retrieved via the REST API.


Make your articles publicly available, which makes them accessible via force.com sites.
The basics are:
  1. Create a Force.com Site
  2. The Public Access Settings for the site must allow access to the Knowledge Article Type object
  3. The site "Public Access Settings" must allow access to the Knowledge Article’s Type fields containing the rich text\images
  4. For the Knowledge Settings, enable "Allow users to share articles via public URLs"
  5. Publish your articles with the "Public Knowledge Base" channel selected.

Once this is done, you would need to then take the returned img src from your API query call, and substitute the domain there with the public site domain name.

So, if your force.com site access url is:

http://mySite.force.com

You'll change your img src in example provided:

FROM (internal access only)

https://c.<instance>.content.force.com/servlet/rtaImage?eid=<ka0....>&feoid=<00N....>&refid=<0EM.....>

TO (Public site access)

http://mySite.force.com/servlet/rtaImage?eid=<ka0....>&feoid=<00N....>&refid=<0EM.....>

Numero articolo Knowledge

000385938

 
Caricamento
Salesforce Help | Article