We have this record in Salesforce with Files attached to it. enter image description here

When I execute this query as an administrator via the developer console, it gives me results:

[SELECT ContentDocumentId, ContentDocument.Title,LinkedEntityId FROM ContentDocumentLink WHERE LinkedEntityId =:contractId]

When I run the same query as a customer portal user it returns zero results.

Knowing that LinkedEntityId matches the id of a record that the portal user has access to, as shown in the image enter image description here

Does anyone know why I don't get any results from this query as a community user or how I can get the public URL for this document via apex?

  • 1
    can you check if portal user has access to the Contract record? – Santanu Boral Jan 16 '18 at 14:40
  • Does it show up if you do it as a child subquery instead? SELECT Id, (SELECT ContentDocumentId, ContentDocument.Title,LinkedEntityId FROM ContentDocumentLinks) FROM Contract WHERE Id =:contractId – Charles T Jan 16 '18 at 15:40

The Visibility field of ContentDocumentLink needs to be “AllUsers”


One way to do this is make a Chatter post, attach the existing Salesforce file to the post, and set the post’s audience to “All with access” then submit the post. This will cause the file to be visible to all users with access to the record the file is shared with.

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.