S-Drive 3.6 Documentation

createPublicDownloadLink

Creates a public, unauthenticated download link to one or more files or folders — usable by anyone with the link, without a Salesforce login. Requires S-URL to be configured on the S-Drive Configuration tab first.

This is a simpler version of createPublicLink if you want a download link.

Unlike createPublicLink, this method doesn't need to know anything about the file's parent record — no parent record Id, parent object name, or relationship field. If you just need a straightforward download link and don't have (or don't want to look up) that parent-record information, this is the simpler option.

How to call this method

global static String createPublicDownloadLink(
    List<String> fileIds,
    String objectFileName,
    Datetime expirationDate,
    String password,
    String IpRange
)

Parameters

Parameter

Type

Required

Description

fileIds

List<String>

Yes

Ids of the files and/or folders to include in the link.

objectFileName

String

Yes

Full API name of the file object, e.g. cg__AccountFile__c.

expirationDate

Datetime

No

When the link expires. If not set, the link doesn't expire.

password

String

No

Password protecting the link — minimum 4 characters.

IpRange

String

No

Two IP addresses, separated by a dash (-), restricting which IPs can use the link.

Return value

Returns a String — the public link.

Example

List<String> fileIds = new List<String>{ 'a003G000007MCVhQAO' };

String publicLink = cg.SDriveTools.createPublicDownloadLink(
    fileIds,
    'cg__AccountFile__c',
    Datetime.now().addDays(7), // link expires in a week
    null,   // no password
    null    // no IP restriction
);