I have Salesforce Files associated with a Contact that I'd like to pluck out the ContentVersion Id in order to display the image on a public-facing Visualforce page (via Sites):

<!-- This is working, and 0682h0000004YQRAA2 is the ContentVersion Id -->
<apex:image url="/sfc/servlet.shepherd/version/download/0682h0000004YQRAA2" />

Within my controller code, I am properly getting the ContentDocumentIds, but the SOQL query on ContentVersion is giving me no results, even though I get results via the Developer Console (when logged in as a System Admin):

// contactId set to a contact with three Files associated with it
List<ContentDocumentLink> cdls = [SELECT Id, ContentDocumentId, LinkedEntityId FROM ContentDocumentLink WHERE LinkedEntityId = :contactId];

Set<Id> docIds = new Set<Id>();
for (ContentDocumentLink cdl : cdls)

System.debug('ContentDocumentIds: ' + docIds);  // Showing three ids

List<ContentVersion> files = 
    [SELECT Id, Title FROM ContentVersion 
     WHERE ContentDocumentId in :docIds AND IsLatest = true];

System.debug('ContentVersion files size: ' + files.size());   // Size is 0...

It seems either:

1) The Guest Site User Public Access settings (i.e. Profile settings) doesn't allow me to access the ContentVersion (right now there are read rights on the Contact within the Guest Site User Profile), or

2) There's some sharing permissions on ContentVersion and friends.

What permissions / settings am I missing?


As told by the answer to this post, there's a Query All Files permission according to the Spring 19 release notes, but I can't see the permission when trying to update the Guest Site User's profile.

  • 3
    is your controlller sharing or without sharing? – Pranay Jaiswal May 13 '19 at 13:47
  • Just updated it to without sharing but still no go – Brian Miller May 13 '19 at 13:50
  • 1
    Is the file here in consideration shared with Internal only or All Users? I think you may need to allow the sharing of files to the community users. Take a look at this answer if that provides a direction. – Jayant Das May 13 '19 at 14:17
  • Great idea, but Visibility on ContentDocumentLink records is already set to 'AllUsers' :-/ – Brian Miller May 13 '19 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.