Salesforce Files API
- 1 Salesforce Files
- 1.1 readSFFile
- 1.2 queryContent
- 1.3 createSFFile
- 1.4 createSFFileFromFilePath
- 1.5 createSFFileFromCamera
- 1.6 deleteSFFile
Salesforce Files
In order to use the below APIs, you must enable Salesforce Files support within Pulsar. Please see "Enable Salesforce Files" for instructions for doing this.
readSFFile
This API call returns an array containing a dictionary with the ContentVersion object for the ContentDocument or ContentVersion matching the Id specified.
Important returned fields:
VersionData
– base64 encoded file data (ifReturnBase64Data
is notfalse
)ThumbBody
– base64 encoded file thumbnail data (ifReturnBase64Data
is notfalse
and the file is an image)FileURL
– local URL to the fileThumbURL
– local URL to the file thumbnail (empty string if file is not an image)
Related Pulsar Settings:
var request = {
"type" : "readSFFile",
"data" : {
"Id" : "069234567891234", // Required ContentDocument or ContentVersion Id
"ReturnBase64Data" : false, // Optional, default true. If false you will still have access to URL of file
"DownloadVersionData" : true, // Optional, default true. If true and online, Pulsar will attempt to download the file from the server to ensure it has the latest version. If false, it will skip this step and use the data is available locally, if it exists.
}
};
bridge.sendRequest(request, function (responseData) { alert('The File is located here: ' + responseData.data[0].FileURL });
Normal data reads through 'select' API will not contain Base64 file data in the VersionData field unless that field has previously been queried from Salesforce or otherwise populated with Base64 data.
queryContent
This API call returns an array of dictionaries representing ContentVersion objects matching the specified filter. The filter is specified in sqlite where clause format, and is applied to objects in the ContentVersion table only. For example "(ContentDocumentId= '069234567891234')" will return all ContentVersions where the ContentDocumentId field is set to 069234567891234. This method will return URLs to a cached version of the File, but will not return the file data directly as in readSFFile.
Important returned fields:
FileURL
– local URL to the fileThumbURL
– local URL to the thumbnail file (empty string if file is not an image)FilePath
- local relative or absolute path to the fileThumbPath
- local relative or absolute path to the file
var request = {
"type" : "queryContent",
"data" : {
/* give us all synced files attached to account with Id 001abc012345678ABC */
"filter" : "ContentDocumentId in (SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = '001abc012345678ABC')",
"DownloadVersionData" : true, // Optional, default true. If true and online, Pulsar will attempt to download the files from the server to ensure it has the latest version. If false, it will skip this step and use the data is available locally, if it exists.
}
};
bridge.sendRequest(request, function (responseData) { alert('The first File is located here: ' + responseData.data[0].FileURL });
createSFFile
var request = {
"type" : "createSFFile",
"data" : {
"ParentId" : "001234567891234", // Required
"Name" : "FileName.jpg", // Required
"Body" : "AABBCCDDEEFF...", // Base64 data -- Required
"ContentType" : "image/jpeg", // Optional -- manual entry of content type
"NetworkId" : "0DB123456789123" // Optional, the NetworkId of the current Experience Cloud site- NOTE: this would be required only for your Salesforce Community Users
}
};
bridge.sendRequest(request, function (responseData) {
if (responseData.type == "createSFFileResponse") {
alert('Created Content Document Id: ' + responseData.data);
}
else {
// error code
}
});