S-Drive 3.6 Documentation

getAttachmentURLs

getAttachmentURLs

Returns temporary, expiring URLs for multiple S-Drive files at once — the batch version of getAttachmentURL, with the added ability to control whether each URL opens the file inline or forces a download.

How to call this method

global static List<String> getAttachmentURLs(List<ID> parentIds, List<ID> fileObjectIds, Long timeValue)

global static List<String> getAttachmentURLs(List<ID> parentIds, List<ID> fileObjectIds, Long timeValue, Map<String,String> requestParameters)

global static List<String> getAttachmentURLs(List<ID> parentIds, List<ID> fileObjectIds, Long timeValue, List<Map<String,String>> requestParametersList)

Three overloads: the first for a plain batch of URLs, the second applies the same extra request parameters to every file in the batch, and the third lets you specify different request parameters per file.

Parameters

Parameter

Type

Required

Description

parentIds

List<ID>

Yes

Salesforce Ids of the parent objects, one per file, in the same order as fileObjectIds. Accepts 15- or 18-character Ids.

fileObjectIds

List<ID>

Yes

Ids of the file records to get URLs for. To get an older version's URL instead of the current one, use that version's file record Id.

timeValue

Long

Yes

How long the URLs stay valid, in seconds.

requestParameters

Map<String,String>

No

Extra request parameters applied to every URL in the batch — most notably response-content-disposition, which controls whether the URL opens the file inline or downloads it (see below). See Amazon's REST GET Object documentation for the full list of supported parameters.

requestParametersList

List<Map<String,String>>

No

Same idea as requestParameters, but one map per entry in fileObjectIds, same order — for setting different parameters per file.

Return value

Returns List<String> — one URL per entry in fileObjectIds, in the same order.

Open URLs vs. download URLs

The response-content-disposition value inside requestParameters controls how the URL behaves when opened:

  • Include "inline" to get an open URL — displays the file in the browser.

  • Include "attachment" to get a download URL — forces a save-to-disk prompt.

Example — download URLs

List<Id> accIds = new List<Id>{ '0013G00000RaoJ3QAJ' }; // parent Account record Id
List<Id> fileIds = new List<Id>{ 'a003G000007MCVhQAO' }; // file record Id

Map<String,String> reqParam = new Map<String,String>{
    'response-content-disposition' => 'attachment; filename=Agreement.pdf'
};

List<String> downloadURLs = cg.SDriveTools.getAttachmentURLs(accIds, fileIds, 212324, reqParam);
String agreementFileURL = downloadURLs[0];

Example — open URLs

Map<String,String> reqParam = new Map<String,String>{
    'response-content-disposition' => 'inline; filename=Agreement.pdf'
};

List<String> openURLs = cg.SDriveTools.getAttachmentURLs(accIds, fileIds, 212324, reqParam);
String agreementFileURL = openURLs[0];