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 |
|---|---|---|---|
|
|
|
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. |
|
|
|
Yes |
Full API name of the file object, e.g. |
|
|
|
Yes |
Id of the parent record — e.g. the Account Id, for account files. |
|
|
|
Yes |
Name of the parent object — e.g. |
|
|
|
Yes |
The relationship field name between the parent and file objects — e.g. |
|
|
|
Yes |
Whether public users can view/read the file(s). |
|
|
|
Yes |
Whether public users can edit the file(s). |
|
|
|
Yes |
Whether public users can delete the file(s). |
|
|
|
Yes |
Whether public users can upload new files or create new folders. |
|
|
|
Yes |
When the link expires. |
|
|
|
No |
Password protecting the link — minimum 4 characters. |
|
|
|
No |
Two IP addresses, separated by a dash ( |
|
|
|
Yes |
If |
|
|
|
Yes |
If |
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
|
|
true |
false |
true |
Download button shows
|
|
true |
true |
false |
Download button shows
|
|
true |
false |
false |
Download button shows
|
|
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
);