2

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)
    docIds.add(cdl.ContentDocumentId);

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?

Update

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.

5
  • 3
    is your controlller sharing or without sharing? May 13, 2019 at 13:47
  • Just updated it to without sharing but still no go May 13, 2019 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, 2019 at 14:17
  • Great idea, but Visibility on ContentDocumentLink records is already set to 'AllUsers' :-/ May 13, 2019 at 14:27
  • hi! what was the solution to this? Oct 3, 2020 at 14:18

2 Answers 2

2

u have first to enable external sharing on the file level: enter image description here

0

That permission is not available for Guest User Profile. That permission is available for System Administrator profile.

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Mar 22 at 10:44

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.