I have created a visualforce page (site) with a dowloadlink from files. I can use this when I am logged in into Salesforce. I want to achieve this for external users by a site. In salesforce It is possible to generate a external link on the attachment. How do I create a this shared link trough apex.

Below is how I currently generate the link url:

    public with sharing class AttachmentfilesExt{
    public List<ContentDocumentLink> idsContentdocument {get;set;}
    public AttachmentfilesExt(Apexpages.StandardController con){
        idsContentdocument = new List<ContentDocumentLink>();
        Id accId  = [SELECT id , Token__c FROM Account WHERE Token__c =:apexpages.currentpage().getparameters().get('token') LIMIT 1].id;
        system.debug('accId: '+ accId);
        idsContentdocument = [SELECT ContentDocument.title, ContentDocumentId,Id,LinkedEntityId,ShareType FROM ContentDocumentLink WHERE LinkedEntityId = :accId];

you can try to use this approach:

 public static String documentDownloadUrl() {
    ContentDocumentLink cdl = //You get in your own way
    return Url.getSalesforceBaseUrl().toExternalForm()
                        + '/sfc/servlet.shepherd/document/download/' 
                        + cdl.ContentDocumentId;
| improve this answer | |

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.