Thursday, February 6, 2020

How to download the files using URL from salesforce

Note: To download the file, require the Content Version record Ids

For Single File

Use the below URL to download the single file from the salesforce.
URL https://<YOUR_SFDC_BASE_URL>/sfc/servlet.shepherd/version/download/068XXXXXXXXXXXX

String idCntDoc = '068XXXXXXXXXXXX';
String strURL = URL.getSalesforceBaseUrl().toExternalForm() + '/sfc/servlet.shepherd/version/download/' + idCntDoc;
System.debug('URL ===> '+strURL);

For Multiple Files

URL: https://<YOUR_SFDC_BASE_URL>/sfc/servlet.shepherd/version/download/068XXXXXXXXXXXX/068XXXXXXXXXXXX
above URL downloads the files in ZIP folder

list<String> lstCntVersionIds = new list<String>{'068XXXXXXXXXXXX', '068XXXXXXXXXXXX'};

String strURL = URL.getSalesforceBaseUrl().toExternalForm() + '/sfc/servlet.shepherd/version/download/';

for(String iterator : lstCntVersionIds) {
    strURL += iterator + '/';
}

strURL = strURL.removeEnd('/');

System.debug('URL ===> '+strURL);

2 comments:

  1. Shaik, I need help with this as I'm getting an error during processing.
    For the SFDC base URL, would that the domain?
    Also, I'm just adding the URL into a browser (Chrome) window.
    Thanks.

    ReplyDelete
  2. thank you this was driving me crazy and this is the only example that worked!

    ReplyDelete