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
- For internal users this link works fine
- Is this the right way to implement my use case?
- Did something change in Salesforce that causes the url now not to work anymore?
- 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)?