Display image stored as a File in object layout. - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Jacob MarshallJacob Marshall 

Display image stored as a File in object layout.

I'm currently in the process of updating an org's custom code to allow us to replace Attachments with Files.  We had a trigger that would previously save an image as an attachment, then use an embedded visualforce page on the layout to display that image.  I've successfully altered the code to save the image as a File, but need assistance in viewing the file in the layout.

The previous (and working) visualforce page to view attachments was updated from this:
<apex:page standardcontroller="Medical_Information_Request__c" standardStylesheets="false" showHeader="false" sidebar="false">
    <img src="/servlet/servlet.FileDownload?file={!Medical_Information_Request__c.SignatureId__c}"/>
SignatureId__c stored the Id of the attachment.  This img src url did not work for files, and I had temporary luck with viewing this image as a file with the following:
<apex:page standardcontroller="Medical_Information_Request__c" standardStylesheets="false" showHeader="false" sidebar="false">
    <img src="/sfc/servlet.shepherd/version/download/{!Medical_Information_Request__c.SignatureId__c}?asPdf=false"/>

In the above, I'm saving the Id of the ContentVersion object that I saved.  Unfortunately, after a refresh when viewing the object page I get this error:

ErrorWhen I try with the ContentDocument Id, the object's layout loads, but the image doesn't.

I can see the file is properly saved and it linked to the object correctly:
User-added image
If I put the SignatureID in the url, it does load:
User-added image
One last curiousity, which might be a red herring, is that the download button on the file page gives a new Id that isn't the ContentDocument Id or the ContentVersion Id:
What object does this Id relate to?

I'd appreciate any assistance :)

EdEd (salesforce.com) 
Hi Jacob,

Will this discussion help?

May I also suggest posting your query over to the developer forums for advice from the developer who may have already implemented the same: