0

I have created a link on a visualforcepage for Guest user.The link shows correctly with the correct id. When I try to download the link a new page is opened with the error: urlsite/ex/errorduringprocessing.jsp'

When I do the same logged in everything works fine. To give permissions I have created 2 triggers 1 to set ContentDocumentLink.visibility = 'AllUsers' and 1 to set ContentVersion.Origin = 'C'.

No errors in my debug logs for Guest user

My url looks fine:

urlsite/sfc/servlet.shepherd/document/download/id

My visualforcepage looks like:

    <apex:page standardController="Account" extensions="AttachmentfilesExt" sidebar="false" showHeader="false">
   <apex:repeat value="{!idsContentdocument}" var="file">
        <a href="{!URLFOR('/sfc/servlet.shepherd/document/download/'+ file.ContentDocumentId)}" target="_blank"> Click here </a>&nbsp;&nbsp;&nbsp;
        {!file.ContentDocument.title} 
        <br/>
    </apex:repeat>
</apex:page>

My controller:

  public without sharing class AttachmentfilesExt{
    public List<ContentDocumentLink> idsContentdocument {get;set;}
    public Id accId;
    public AttachmentfilesExt(Apexpages.StandardController con){
        idsContentdocument = new List<ContentDocumentLink>();
        try{
            string token = apexpages.currentpage().getparameters().get('token');
            system.debug('token: '+ token);
            accId  = [SELECT id , Token__c FROM Account WHERE Token__c =:token LIMIT 1].id;
            system.debug('accId: '+ accId);
        }
        catch(Exception e){
            System.debug('An exception accId occurred: ' + e.getMessage());
        }
        try{
            system.debug('accId 2: '+ accId);
            idsContentdocument = [SELECT ContentDocument.title, ContentDocumentId,LinkedEntityId FROM ContentDocumentLink WHERE LinkedEntityId = :accId];//:con.getId()
        }
        catch(Exception e){
            System.debug('An exception idsContentdocument occurred : ' + e.getMessage());
        }
    }
}
  • You are allowing guest users to download files via community? – RedDevil May 18 at 12:56
  • @RedDevil No trough sites – Thomas May 18 at 13:13
  • It works for me for communities guest user, can you check these things 1.Site guest user has access to the account record under which the files are there 2.Site guest user profile has read access for account object. – RedDevil May 18 at 14:46
  • @RedDevil Yes guest user has acces to these. I decided to go another route trough ContentDistribution. Only issue I have now is to do apex repeat on ContentDistribution.DistributionPublicUrl. If I pass this into a set it works not from the list from where I easily can get the name of the document. – Thomas May 18 at 15:17
0

For those who are looking for this solution I solved this with a map on name and ContentDownloadURL from ContentDistribution

Visualforce:

 <apex:repeat value="{!urlmap}" var="key">    
 <apex:outputLink value="{!urlmap[key]}">Click here to download</apex:outputLink>&nbsp;{!key}<br/>
   </apex:repeat>

Controller:

try{
   urlsContentDistribution = [SELECT DistributionPublicUrl, ContentDownloadURL ,name FROM ContentDistribution WHERE RelatedRecordId = :accId];
    for(ContentDistribution m:urlsContentDistribution){
        urlmap.put(m.name,m.ContentDownloadURL);
    } 
}
catch(Exception e){
    System.debug('An exception idsContentdocument occurred : ' + e.getMessage());
}

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.