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 |
|---|---|---|---|
|
|
|
Yes |
Salesforce Ids of the parent objects, one per file, in the same order as |
|
|
|
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. |
|
|
|
Yes |
How long the URLs stay valid, in seconds. |
|
|
|
No |
Extra request parameters applied to every URL in the batch — most notably |
|
|
|
No |
Same idea as |
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];