S-Drive 3.6 Documentation

createPublicLink

Creates a public, unauthenticated access 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.

To use this method, you must have surl/Public Share enabled and configured.

Unlike getAttachmentURL / getAttachmentURLs, which hand a URL to your own Salesforce-side code, this method is for sharing with people outside your org entirely — with its own access controls (read/update/delete/create, password, IP range) since there's no Salesforce login to fall back on.

How to call this method

global static String createPublicLink(
    List<String> fileIds,
    String objectFileName,
    String objectId,
    String objectName,
    String objectRelationshipName,
    Boolean isAccessible,
    Boolean isUpdatable,
    Boolean isDeletable,
    Boolean isCreatable,
    Datetime expirationDate,
    String password,
    String IpRange,
    Boolean isDownloadLink,
    Boolean isOpen
)

Parameters

Parameter

Type

Required

Description

fileIds

List<String>

Yes

Ids of the files and/or folders to include in the link. NOTE: All files/folders must belong to the same parent--i.e. the same Account or the same Contact, etc.

objectFileName

String

Yes

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

objectId

String

Yes

Id of the parent record — e.g. the Account Id, for account files.

objectName

String

Yes

Name of the parent object — e.g. "Account", for account files.

objectRelationshipName

String

Yes

The relationship field name between the parent and file objects — e.g. "Account__r" for account files.

isAccessible

Boolean

Yes

Whether public users can view/read the file(s).

isUpdatable

Boolean

Yes

Whether public users can edit the file(s).

isDeletable

Boolean

Yes

Whether public users can delete the file(s).

isCreatable

Boolean

Yes

Whether public users can upload new files or create new folders.

expirationDate

Datetime

Yes

When the link expires.

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.

isDownloadLink

Boolean

Yes

If true, opening the link downloads the file.

isOpen

Boolean

Yes

If true, the file opens inside the S-Drive component.


How the parameters work together

  • For download links, isAccessible and isOpen don’t make any difference

  • For Access links, isOpen makes no difference. isAccessible should be set to true. Otherwise the list of files can be seen, but nothing can be done with them.

  • Best practices: Always set isAccessible and isOpen to true.

isDownloadLink

isAccessible

isOpen

Result

true

true

true

Download button shows
files download/open

true

false

true

Download button shows
files download/open

true

true

false

Download button shows
files download/open

true

false

false

Download button shows
files download/open

false

true

true

S-Drive component shows with files listed

Files can be opened/downloaded

false

false

true

S-Drive component shows with files listed

Files cannot be opened/downloaded.

false

true

false

S-Drive component shows with files listed

Files can be opened/downloaded

false

false

false

S-Drive component shows with files listed

Files cannot be opened/downloaded.



Return value

Returns a String — the public link.

Example

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

String publicLink = SDriveTools.createPublicLink(
    fileIds,
    'cg__AccountFile__c',
    acct.Id,
    'Account',
    'Account__r',
    true,   // isAccessible — public users can view the file
    false,  // isUpdatable
    false,  // isDeletable
    false,  // isCreatable
    Datetime.now().addDays(7), // link expires in a week
    null,   // no password
    null,   // no IP restriction
    true,   // isDownloadLink
    false   // isOpen
);