function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Will Johnston 34Will Johnston 34 

Content objects not returned in queries run by public guest/site user

When associating a Salesforce File to an object in the UI, the associated ContentDocumentLink and ContentVersion records are not returned when the public guest/site user queries for them. An internal Salesforce user can query for them fine. I've tried updating sharing settings, changing owners, and verified my query runs without sharing. The only thing that seems to work is if I recreate those objects in apex, then the user can query for them.

Has anyone run into this? Is there a way for the site user to have access without recreating the objects in apex?
Glyn Anderson (Slalom)Glyn Anderson (Slalom)
Will, More information required:  What license is the Guest profile using (Customer, Customer Plus, Partner)?  What is the object you're associating the file to?  Are the files in a Library?
Will Johnston 34Will Johnston 34
The user has a Guest License. We would like to upload a Salesforce File to an Opportunity and then allow the guest user to access it from an externally available site. The files are not in a Library. Thanks!
Glyn Anderson (Slalom)Glyn Anderson (Slalom)
Sorry, Will, I'm still confused.  Is "the user" an internal user with some sort of Guest profile?  Or do you have a Community that has unauthenticated users (i.e. Guest Users)?  If the latter, there will be a Guest User profile associated with the Community, and that in turn, will have a Community license associated to it -- either Customer Community License, Customer Community Plus License, or Partner Community License (or the "Login" flavor of one of those).  As far as I can tell, Salesforce doesn't have a "Guest License".  The type of Community license will inform whether the unauthenticated users will be able to see Content within the Community.  Content is not available to the Customer Community License; but it is with Customer Community Plus and Partner Community Licenses.  (BTW: Opportunities are only available to the Partner Community License.)  Let me know what you find, and we'll keep working at a solution.  Thanks!
Glyn Anderson (Slalom)Glyn Anderson (Slalom)
From this Help Document https://help.salesforce.com/articleView?id=users_license_types_communities.htm&type=5

User-added image


Note that "Files" are available to Customer Community, but that would be Files uploaded to Chatter, as opposed to Files attached to records (I'm pretty sure...).
Will Johnston 34Will Johnston 34
Thanks for the replies. The user in isn't a Community user but instead a site user accessing a public and external Force.com site. It seems like there are different permissions on the ContentDocumentLink and ContentVersion objects for that type of user. 
Will Johnston 34Will Johnston 34
I believe I found a workaround here. Creating a before insert trigger on ContentVersion that sets the Origin field to C, along with a before insert trigger on ContentDocumentLink that sets Visibility to AllUsers, allowed the public force.com site guest user to access the Salesforce File which was uploaded by the out of the box UI. So records started being returned when querying ContentDocumentLink and ContentVersion as the site user after uploading with those trigger changes in place.