I am using an old portal for my customers, with customer community user licenses.

In the portal, my users should upload files and then download the files that they have uploaded.

The portal is written in VisualForce pages, and the file mechanism is written in a lightning component with lightning out.

Uploading the file with apex, I am creating a ContentDocumentLink record with the field Visibility='AllUsers' - this is how the file should be available in the community:

// insert a version of the file - if no ContentDocumentId, then it creates a new ContentDocument
ContentVersion cv = new ContentVersion();
cv.ContentLocation = 'S'; // S = within Salesforce, E = External
cv.VersionData = body;
cv.Title = 'fileName';
cv.PathOnClient = 'filename';
insert cv;


cv = [SELECT Id, ContentDocumentId FROM ContentVersion WHERE Id =: cv.Id LIMIT 1];
ContentDocumentLink cdl = new ContentDocumentLink();
cdl.ContentDocumentId = cv.ContentDocumentId;
cdl.LinkedEntityId = parentRecordId;
cdl.ShareType = 'V';
cdl.Visibility = 'AllUsers';
insert cdl;

In my community I use a link to download the file:

<a href="https://yadhanadiv.my.salesforce.com/sfc/servlet.shepherd/version/download/0680y0000035XwEAAU" target="_blank">myFileName</a>

In the past, this method worked OK, and clicking on this link would download the file.

Today, this link is not working for a community user - whenever I am trying to access that url from the user, I get redirected to Salesforce login page with a red text error: To access this page, you have to log in to Salesforce

enter image description here

  • For internal users this link works fine

QUESTIONS

  1. Is this the right way to implement my use case?
  2. Did something change in Salesforce that causes the url now not to work anymore?
  3. Is there a way to fix it or to implement in a different way so my users could download the files that they have uploaded (The file ownership is the community user itself)?
  • 1
    The link in your a href redirects to your Org and not the Community https://yadhanadiv.my.salesforce.com and thus it seems it always leads you to the login page. Have you tried using your Community URL to access the same servlet resource, something as https://mycommunity.force.com/rest of the url. – Jayant Das Dec 5 at 13:58
  • Good catch @JayantDas – Pranay Jaiswal Dec 6 at 10:22
  • 1
    @JayantDas it worked!!!! thank you so much. can you please write that as an answer so I can accept it and you can also be rewarded? – Itai Shmida Dec 9 at 10:57
  • Glad that it worked. Added an answer so that it also helps anyone else in same scenario. – Jayant Das Dec 9 at 16:12
up vote 1 down vote accepted

Rolling up comment as answer.

The link in your a href redirects to your Org https://yadhanadiv.my.salesforce.com and not the Community, and thus it always leads you to the login page.

To redirect to your Community URL to access the same servlet resource, you should point it to the Community url, something as https://mycommunity.force.com/rest of the url

As per this Knowledge Article files created before a community exist cannot be shared with the community.
However, any file that is created after the community is created can be shared with the community. If there is a ContentDocumentLink with Visibility=AllUsers and the LinkedEntityId is pointing to the Org, that file will be visible on the community.
So the best solution would be to create a trigger to make sure all relevant files will get the correct sharing settings. Then use Data Loader to download, delete and re-upload all your files.
It could be a side effect of with the new way files are shared in communities in Winter '19. Release Notes.

  • Thank you @AvailableName although the case you have shared here is real, it does not solve my problems - I am trying to download my own files that I have just uploaded to the community, with the same user and the same community that exists for more than a year now. – Itai Shmida Dec 9 at 11:00

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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