6

We're querying ContentDocumentLink for a list of documents related to a specific object record that the user has access to, and attempting to create a link for the community user to download that document. We're finding the ContentDocument ID in ContentDocumentLink.LatestPublishedVersion.Id. The LEX link of /sfc/servlet.shepherd/version/download/{ID} works fine from the Org domain, but I am not finding an equivalent for the Community domain. The error I receive is that the "community is down for maintenance". I've tried a number of variations and mixtures of this and /lightning/r/ContentDocument/{ID}/view. Is this something that can be done in Lightning Communities?

We are building this page using Skuid (basically html in this particular case), so we are not able to use an Aura or LWC solution.

4 Answers 4

7

The download link on the file previewer in a community generates a link of this format.

It should work fine for your scenario with the exception of not being a best practice to hardcode it like this.

/sfc/servlet.shepherd/document/download/{id}?operationContext=S1
4
  • No dice. I still get the "Down for Maintenance" error page.
    – Jerbot
    Commented May 2, 2019 at 19:49
  • @SuperJer Can you navigate to the file viewer in the community and see what the download links look like in your specific environment? /s/contentdocument/069{theRestOfTheContentId}
    – Mark Pond
    Commented May 2, 2019 at 21:27
  • Hmm. I get an "Invalid Page" when navigating there in the runtime, and a "We can't load this page because it's missing some underlying data" error in the communities builder.
    – Jerbot
    Commented May 3, 2019 at 19:59
  • Just a quick note when using this. You want to grab the URL base from your Communities page and the /sfc/servlet.shepherd/document/download/{id}?operationContext=S1 comes right after the .com
    – Joseph U.
    Commented Jan 14, 2022 at 19:28
3

Salefsorce might add /s/ to your URL, making download link invalid.

When you build your URL with:

/sfc/servlet.shepherd/document/download/{id}?operationContext=S1

and hover your mouse over it on the page, you'll see:

https://domain.cs80.force.com/sfc/servlet.shepherd/document/download/{id}?operationContext=S1

but when you click on it, what you actually get is (note the /pageName/s/):

 https://domain.cs80.force.com/pageName/s/sfc/servlet.shepherd/document/download/{id}?operationContext=S1

now, the correct url should look like this (the same as above, but with /s removed:

https://domain.cs80.force.com/pageName/sfc/servlet.shepherd/document/download/{id}?operationContext=S1

To do it, you can simply build your url in controller, using:

window.location.href + '/pageName/sfc/servlet.shepherd/document/download/{id}?operationContext=S1'

1
  • how to get the host URL of the contentdocument? salesforce internally redirecting from c.visualforce.com to c.documentforce.com. This is consuming extra browser connections. Commented Nov 26, 2021 at 9:19
2

This one is working correctly in our community :

/sfc/servlet.shepherd/document/download/{ContentDocumentId}?operationContext=S1
0

This is working for me: /customer/sfc/servlet.shepherd/version/renditionDownload?rendition=THUMB720BY480&versionId={versionId}&operationContext=COMMUNITY&contentId={contentId}&page=0

1
  • 2
    This looks to be very similar to the existing answers from ~5 years ago, just with Id values that could only possibly work for you. Please edit your answer to use placeholders for the Ids (like the existing answers do) and explain what is different about your answer. If you know why it works, all the better (and you should include that knowledge in your answer). If this is something along the lines of "the old way doesn't work any more. This started working as of version x.xx", then that's also important information to include.
    – Derek F
    Commented Jun 13 at 16:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .