I'm working on a project where I'll be using VisualForce to render custom PDF service reports. So my page will take in the ID of a Service object (from Field Service Lightning) and populate all the data from there and its related records. One requirement is that we be able to take attached signature images and include them in the report.

I see there are many ways to attach files including "Notes & Attachments" and "Files". We'd prefer to use Files as it's a newer feature set. However I have only managed to do this successfully with Attachments so far. This is my working code that displays all related Attachment images:

<apex:repeat value="{!CKSW_BASE__Service__c.Attachments}" var="att">
    <apex:image url="{!URLFOR($Action.Attachment.Download, att.id)}"
        rendered="{!contains(att.ContentType, "image")}" />

So you can see I grab the entire Attachments related list, I use the global $Action provider to generate a URL for the attachment, and then render it only if it is actually an image.

But what do I do if the image was attached using the Files feature (which I understand has the API name ContentVersion) instead of Attachments? What is the structure of the related lists I can use, if any, and can I fetch the URL using URLFOR rather than hard-coding /sfc/servlet.shepherd/version/download/{id}? I am not finding this to be well-documented.

EDIT: Okay I found the related list... I would have to iterate over CKSW_BASE__Service__c.ContentDocumentLinks and then get the LatestPublishedVersion property to have the ContentVersion ID. But I am stuck on finding a way to use URLFOR with this object.

  • As far as I can say this may be not straightforward. Action supports Download option only for 2 objects 1) Attachment 2) Document. You may have to convert the content to an attchment/ doc and render it on the vf page if you want to continue with your current approach. developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/…
    – Rao
    Oct 21, 2016 at 18:29
  • I'm able to render the image just fine if I link to /sfc/servlet.shepherd/version/download/{!ContentVersionId}. The question is, am I risking that this URL becomes deprecated? I could make it marginally more modular by storing the URL in a Custom Setting so it can be altered without editing VF.
    – Charles T
    Oct 21, 2016 at 20:00


Browse other questions tagged .