
Add an image on External Document formats like EXCEL/PDF/WORD
Problem: While adding an image on any of the formats above mentioned, the image was not displayed, instead, an error message is displayed, “This Image cannot be displayed”.
Solution: The possible solution was that the image while after being referenced in the external the document requires authentication outside our Salesforce Org. Explanation: I came across a requirement, for adding an image to the external document like EXCEL/PDF/WORD that has been saved in DOCUMENTS of a Salesforce Org. The very common idea is to use the URL of the image stored in Documents and attach it in “<apex: image>” tag. But while using URL of the image stored in Documents, I came across an error. “This Image cannot be displayed”.

- Open Documents on your Salesforce Org

- Select whichever file is to be used externally

- Now either press “Ctrl + Shift + I” to open “Inspect Element” or right click on the Image and click on INSPECT. After opening INSPECT Element you’ll come across a page like : –

- Now copy the URL from “src” attribute given in the “<img>” tag, as this URL contains a unique “oid”, which is ORGANIZATION ID. This “oid” provides an authentication to access the image file outside org.

- Now in codes, we can use image Url either directly in “<apex: image>” tag, by passing the above-selected Url from Inspect Element in “URL” attribute of “<apex: image>” tag or using “<img>” tag and passing URL directly in “src” attribute.
<img src=”https://c.ap5.content.force.com/servlet/servlet.ImageServer?id=0157F0000002hDx&oid=00D7F000005VpIm&lastMod=1520949532000″/>
<apex: image url=”https://c.ap5.content.force.com/servlet/servlet.ImageServer?id=0157F0000002hDx&oid=00D7F000005VpIm&lastMod=1520949532000″/>
- Another method to access is using getter/setter: –
ImgStatic = ‘https://c.ap5.content.force.com/servlet/servlet.ImageServer? id=0157F0000002hDx&oid=00D7F000005VpIm&lastMod=1520949532000’;
