Table of contents
  1. ClientApi
    1. Constructors
      1. global ClientApi()
        1. Example
    2. Fields
      1. global documentLibraryIdstring
      2. global namedCredentialNamestring
      3. global sharepointSiteIdstring
    3. Methods
      1. global Boolean copyItem(string itemId, string parentFolderId)
      2. global Boolean copyItem(string itemId, string parentFolderId, string destLibraryId)
      3. global Boolean copyItem(string itemId, string parentFolderId, string destLibraryId, string newFileName)
        1. Parameters
        2. Returns
      4. global SharePointFileInfo createFolder(string parentFolderId, string folderName)
        1. Parameters
        2. Returns
        3. Example
      5. global String createSharingLink(String itemId)
      6. global String createSharingLink(String itemId, String type)
      7. global String createSharingLink(String itemId, String type, DateTime expirationDateTime)
      8. global String createSharingLink(String itemId, String type, DateTime expirationDateTime, String password)
      9. global String createSharingLink(String itemId, String type, DateTime expirationDateTime, String password, String scope)
      10. global String createSharingLink(String itemId, String type, DateTime expirationDateTime, String password, String scope, List<string> recipients)
        1. Parameters
        2. Returns
      11. global SharePointFileInfo createURLFile(string parentFolderId, string itemId)
        1. Parameters
        2. Returns
      12. global SharePointFileInfo createURLFile(string parentFolderId, string fileName, string url)
        1. Parameters
        2. Returns
      13. global Boolean deleteItem(string itemId)
        1. Parameters
        2. Returns
      14. global ContentVersion downloadFile(string fileId)
        1. Parameters
        2. Returns
        3. Example
      15. global List<SharePointDocumentLibrary> getDocumentLibraries()
        1. Returns
        2. Example
      16. global string getDocumentLibraryRootFolderId()
        1. Returns
        2. Example
      17. global list<SharePointFileInfo> getFolderContents(string folderId, Boolean getNextPage)
        1. Parameters
        2. Returns
        3. Example
      18. global SharePointFileInfo getItemById(string itemId)
        1. Parameters
        2. Returns
        3. Example
      19. global SharePointFileInfo getItemByPath(string path)
        1. Parameters
        2. Returns
        3. Example
      20. global SharePointUrlResponse getItemBySharePointURL(string sharePointUrl)
        1. Parameters
        2. Returns
        3. Example
      21. global SharePointFileInfo getItemIdByGuid(string guid)
        1. Parameters
        2. Returns
      22. global string getItemPreviewUrl(string itemId)
        1. Parameters
        2. Returns
      23. global string getListItemIdFromLibraryId(string libraryId)
        1. Parameters
        2. Returns
      24. global List<SharePointSite> getSites()
        1. Returns
      25. global List<SharePointSite> getSites(string hostname)
        1. Parameters
        2. Returns
        3. Example
      26. global string getUploadSessionURL(string destinationFolderId, string fileName, boolean replaceFile)
        1. Parameters
        2. Returns
      27. global boolean morePagesAvailable()
        1. Returns
      28. global SharePointFileInfo moveItem(string itemId, string parentFolderId)
        1. Parameters
        2. Returns
      29. global SharePointFileInfo renameFile(string fileId, string newName)
        1. Parameters
        2. Returns
      30. global SharepointFileInfo setupFolder(string recordId, string parentFolderId, string objectSettingsLabel)
        1. Parameters
        2. Returns
      31. global SharePointFileInfo updateCustomFields(string fileId, Map<String,String> customFields)
        1. Parameters
        2. Returns
        3. Example
      32. global SharePointFileInfo uploadFile(string parentFolderId, string fileName, Blob fileContents)
        1. Parameters
        2. Returns
        3. Example
      33. global SharePointFileInfo uploadFile(string parentFolderId, string fileName, Blob fileContents, string recordId, map<string,string> customFields)
        1. Parameters
        2. Returns
        3. Example
      34. global SharePointFileInfo uploadLargeFile(string parentFolderId, string fileName, string documentVersionId)
      35. global SharePointFileInfo uploadLargeFile(string parentFolderId, string fileName, string documentVersionId, string recordId, map<string,string> customFields)
      36. global SharePointFileInfo uploadLargeFile(string parentFolderId, string fileName, string documentVersionId, string recordId, map<string,string> customFields, Boolean autodelete)
      37. global SharePointFileInfo uploadLargeFile(string parentFolderId, string fileName, string documentVersionId, string recordId, map<string,string> customFields, Boolean autodelete, Boolean replaceFile)
        1. Parameters
        2. Returns
        3. Example
      38. global void writeDebugInfo()
    4. Classes
      1. clientApiException

ClientApi

This class allows a Salesforce Developer to leverage the sFiles application to code custom behavior. The API allows the developer to create, delete and update metadata fields for files and folders.

Constructors

global ClientApi()

Initializes the class. This class is only available to organizations with the API Access permission enabled. All method in the ClientApi class require that namedCredentialName, sharepointSiteId and documentLibraryId are all set to valid values. All methods in ClientApi will make callouts, so you cannot execute any DML operations prior to calling a method. Be sure to reserve DML operations until after ClientApi methods are complete.

In the example below, notice that these values can be pulled from either the SharePoint Settings or SharePoint Object Settings metadata types.

Example

//get auth info from the Settings MDT
fileforcem1__SharePoint_Settings__mdt orgSettings = [SELECT fileforcem1__Named_Credential__c,fileforcem1__Document_Library_Id__c,fileforcem1__Site_Id__c FROM fileforcem1__SharePoint_Settings__mdt WHERE Developername = 'Default' limit 1];
//get the root folder id for the account object
fileforcem1__SharePoint_Object_Settings__mdt objectSettings = [SELECT fileforcem1__Root_Folder_Id__c,fileforcem1__Site_Id__c,fileforcem1__Document_Library_Id__c FROM fileforcem1__SharePoint_Object_Settings__mdt WHERE MasterLabel ='Account' LIMIT 1 ];
//Initialize the client object
fileforcem1.ClientApi apiClient = new fileforcem1.ClientApi();
apiClient.namedCredentialName = String.isNotBlank(objectSettings.fileforcem1__Named_Credential__c) ? objectSettings.fileforcem1__Named_Credential__c : orgSettings.fileforcem1__Named_Credential__c;
apiClient.sharepointSiteId = objectSettings.fileforcem1__Site_Id__c;
apiClient.documentLibraryId = objectSettings.fileforcem1__Document_Library_Id__c;

Fields

global documentLibraryIdstring

The Document Library Id that will be used for the SharePoint Operation. This can be pulled from one of the metadata settings or with the ID Utility. This value is required.

global namedCredentialNamestring

Specify which named credential to use for SharePoint operations. If the ClientApi class is called from a trigger or user-initiated action, this can be a “per user” named credential. If the code is to be called from scheduled apex, a platform event trigger or any other system-initiated process, use a “named principal” named credential that corresponds to a SharePoint user with appropriate access. This value can be pulled from one of the metadata settings or from your named credentials list. This value is required.

global sharepointSiteIdstring

The SharePoint site id that will be used for the SharePoint Operation. This can be pulled from one of the metadata settings or with the ID Utility. This value is required.


Methods

global Boolean copyItem(string itemId, string parentFolderId)

global Boolean copyItem(string itemId, string parentFolderId, string destLibraryId)

global Boolean copyItem(string itemId, string parentFolderId, string destLibraryId, string newFileName)

Copy a file or folder and its descendants from one folder in SharePoint to another. Use this to have a Salesforce-triggered backup or publishing of a folder, for instance.

Parameters

Param Description
itemId The SharePoint id of the file or folder that is to be copied.
parentFolderId The SharePoint folder id to copied the item to.
destLibraryId (optional) Specifies the destination document library to copied to. Must be in the same site as the ClientApi instance.
newFileName (optional) A new file or folder name to give the copied item. If filename, include the extension.

Returns

Type Description
Boolean A boolean that returns true if the item copied successfully and false if it did not.

global SharePointFileInfo createFolder(string parentFolderId, string folderName)

Create a folder within a specified folder. The parentFolderId can be obtained from the ID utility or set from the SharePoint_Id__c field on a record.

In the example below, the client is initialized from Metadata settings shared by sFiles. After this is complete, the folder is created. The resulting SharePointFileInfo object is then utilized to record the SharePoint Folder Id on the account.

Parameters

Param Description
parentFolderId Must be an existing folder within the Site and Document Library that the user has access to.
folderName The name that you want to give the folder. Be sure to clean your string of forbidden folder name characters.

Returns

Type Description
SharePointFileInfo A SharePointFileInfo object of the new folder.

See SharePointFileInfo

Example

Account acct = [SOQL STATEMENT HERE];
//Create the account folder and record the ID
fileforcem1.SharePointFileInfo acctFolder = apiClient.createFolder(objectSettings.fileforcem1__Root_Folder_Id__c, acct.Name);
acct.SharePoint_Folder_Id__c = acctFolder.Id;
update acct;

global String createSharingLink(String itemId)

global String createSharingLink(String itemId, String type)

global String createSharingLink(String itemId, String type, DateTime expirationDateTime)

global String createSharingLink(String itemId, String type, DateTime expirationDateTime, String password)

global String createSharingLink(String itemId, String type, DateTime expirationDateTime, String password, String scope)

global String createSharingLink(String itemId, String type, DateTime expirationDateTime, String password, String scope, List<string> recipients)

Create a sharing link.

Parameters

Param Description  
itemId A string with the SharePoint Id of the folder or file to share.  
type (Optional) The type of sharing link to create. Defaults to “view”. (view edit)
expirationDateTime (Optional) A String with format of yyyy-MM-ddTHH:mm:ssZ of DateTime. Defaults to never expire or to default expiration policy of organization.  
password (Optional) The password of the sharing link.  
scope (Optional) The scope of the link to create. “anonymous” or “organization” or “users”. Anonymous allows anyone with link to access without signing in. Organization allows only those signed into your tenant to use the link. Users will only share the link with individual recipients and requires that the recipients list is populated  
recipients (Optional) When sharing to specific email addresses, provide the email addresses in a list of string  

Returns

Type Description
String A string of the sharing link created.

global SharePointFileInfo createURLFile(string parentFolderId, string itemId)

Creates a url file for a SharePoint Item.

Parameters

Param Description
parentFolderId The id of the SharePoint folder where the url file will be created.
itemId The SharePoint Item that the url file will link to.

Returns

Type Description
SharePointFileInfo A SharePointFileInfo object of the URL file created.

global SharePointFileInfo createURLFile(string parentFolderId, string fileName, string url)

Creates a url file for a link outside of SharePoint.

Parameters

Param Description
parentFolderId The id of the SharePoint folder where the url file will be created.
fileName the name of the url file ex.’My File’.
url the URL that the url file will link to.

Returns

Type Description
SharePointFileInfo A SharePointFileInfo object of the URL file created.

global Boolean deleteItem(string itemId)

Deletes a file or folder in SharePoint

Parameters

Param Description
fileId The Id value from a SharePointFileInfo object

Returns

Type Description
Boolean A boolean that returns true if the item deleted successfully and false if it did not.

global ContentVersion downloadFile(string fileId)

Download file from SharePoint. This method takes a SharePoint file id and retrieves the file from SharePoint. It then saves the file in Salesforce Files as a ContentDocument. It then returns the newly created ContentVersion record which can be used in additional automation. If the file is larger than ~5MB the method will return an error, this is dependent on the heap size for executing code. The heap limit is increased if this method is called as a future or queueable. The example below shows downloading a file from SharePoint based on file Id.

Parameters

Param Description
fileId Id of existing file to download, within a Site and Document Library that the user has access to.

Returns

Type Description
ContentVersion A ContentVersion of the file downloaded from SharePoint.

Example

ContentVersion myDownloadedFile = apiClient.downloadFile(fileId);

global List<SharePointDocumentLibrary> getDocumentLibraries()

Get a list of all document libraries in a given site that is set in the ClientApi instance.

Returns

Type Description
List<SharePointDocumentLibrary> A list of SharePointDocumentLibrary objects of the Document Libraries in the SharePoint Site.

Example

//Get Document Libraries for a given site
List<fileforcem1.SharePointDocumentLibrary> myDocumentLibraries = apiClient.getDocumentLibraries();

global string getDocumentLibraryRootFolderId()

Get the Id for a document library root folder.

Returns

Type Description
string The Id of the Root Folder of the Document Library

Example

//Set the Site and Document Library to getId
 apiClient.sharepointSiteId = 'yourSiteId';
apiClient.documentLibraryId = 'yourDocumentLibraryId';
 //Get the Document Library Root Id
String myDocumentLibraryRootFolderId = apiClient.getDocumentLibraryRootFolderId();

global list<SharePointFileInfo> getFolderContents(string folderId, Boolean getNextPage)

Query and list the contents of a folder. * This method will return a list of SharePointFileInfo objects of up to 200 results. If there are more results available after the query, * morePagesAvailable will return true. To query the next page, set getNextPage to true.

Parameters

Param Description
folderId The SharePoint folder id usually pulled from a record’s SharePoint_Folder_Id__c field.
getNextPage Set to true in order to query the next page from the last query in the current running context. Set to false to get the first page.

Returns

Type Description
list<SharePointFileInfo> A list of SharePointFileInfo objects of the items in the folder.

Example

list<fileforcem1.SharePointFileInfo> firstPageContents = apiClient.getFolderContents(ParentFolderId, false);
if (apiClient.morePagesAvailable()){
list<fileforcem1.SharePointFileInfo> secondPageContents = apiClient.getFolderContents(ParentFolderId, true);
}

global SharePointFileInfo getItemById(string itemId)

Searches the Site/Document Library for a file by SharePoint Id

Parameters

Param Description
itemId The SharePoint Id value from a sharepoint file or folder

Returns

Type Description
SharePointFileInfo A SharePointFileInfo object of the SharePoint item found.

Example

//Get the folder
fileforcem1.SharePointFileInfo acctFolder = apiClient.getItemById(objectSettings.fileforcem1__Root_Folder_Id__c);

global SharePointFileInfo getItemByPath(string path)

Retrieves a single file or folder by specifying the path to the file in a document library. This allows automation options such as retrieval of SharePoint folder ids to set the Sharepint_Folder_Id__c on a record. In the example below, a SharePoint Folder Id is retrieved by querying its path within the document library.

Parameters

Param Description
path The path within the Document Library to a file or folder. For instance, “/Accounts/Bob’s Account” would return the “Bob’s Account” folder information. It must have the slash at the beginning. Relative folder paths such as ../ or ./ are not available.

Returns

Type Description
SharePointFileInfo A SharePointFileInfo object of the SharePoint item found.

Example

string folderPath = '/Accounts/Bob\'s Account';
fileforcem1.SharepointFileInfo folderInfo = apiClient.getItemByPath(folderPath);
string folderId = folderInfo.Id;

global SharePointUrlResponse getItemBySharePointURL(string sharePointUrl)

When provided with a URI directly from a SharePoint Location. This method Retrieves a SharePointUrlResponse class which returns the following when successful. Will throw an APIException if there is an error.
- ID’s of the URL’s folder, document library, document library folder and site
- SharePointFileInfo objects of the URL’s folder, document library and site

Parameters

Param Description
sharePointUrl A url that is copied from the browser location of a folder within SharePoint.

Returns

Type Description
SharePointUrlResponse A SharePointFileInfo object of the SharePoint item found.

Example

string folderUrl = 'https://yoursite.sharepoint.com/sites/yourSite/Shared%20Documents/Forms/AllItems.aspx?RootFolder=%2Fsites%2FyourSite%2FShared%20Documents%2FAccounts%2FBurlington%20Textiles%20Corp%20of%20America&FolderCTID=0x01200000DE969EFDB44E4AA3DECBD9AD27C498';
SharePointUrlResponse myItem = apiClient.getItemBySharePointURL(folderUrl);
System.debug('Folder Id: ' + myItem.folderId);

global SharePointFileInfo getItemIdByGuid(string guid)

Searches the Site/Document Library for a file by SharePoint GUID.

Parameters

Param Description
guid The GUID value from a SharePoint file or folder.

Returns

Type Description
SharePointFileInfo A SharePointFileInfo object of the SharePoint item found.

global string getItemPreviewUrl(string itemId)

Gets the temporary url for the preview of the file.

Parameters

Param Description
itemId The item Id.

Returns

Type Description
string A string of the temporary url to preview the file.

global string getListItemIdFromLibraryId(string libraryId)

This method takes a Document Library ID and returns a list item Id.

Parameters

Param Description
libraryId The id of the Document Library

Returns

Type Description
string The list item id of the Document Library

global List<SharePointSite> getSites()

Get a list of all sites in the root of your SharePoint domain as specified in the “Default” custom metadata type “SharePoint Settings”.

Returns

Type Description
List<SharePointSite> A list of SharePointSite objects of each site in the domain specified in the SharePoint Settings.

global List<SharePointSite> getSites(string hostname)

Get a list of all sites in a domain.

Parameters

Param Description
hostname The SharePoint hostname or site Id to get the list of sites from. E.g., myothersite.sharepoint.com or mysite.sharepoint.com,123f4bd5-678e-991e-b8c7-54e93f81d3ac,123e4e5d-678a-9f1e-1f23-45adba6789ad

Returns

Type Description
List<SharePointSite> A list of SharePointSite objects of each site in the domain specified as a parameter.

Example

//Get sites
List<fileforcem1.SharePointSite> mySites = apiClient.getSites('mysite.sharepoint.com,123f4bd5-678e-991e-b8c7-54e93f81d3ac,123e4e5d-678a-9f1e-1f23-45adba6789ad');

global string getUploadSessionURL(string destinationFolderId, string fileName, boolean replaceFile)

Provides a one-time url to upload a file to the specified folder. This is designed to be used with custom client-side javascript to upload a file directly to a location. This method is useful to customers only under certain conditions. Please contact support to determine if this can be used in your solution.

Parameters

Param Description
destinationFolderId The id of the folder to upload into
fileName the name of the file to be uploaded along with extension
replaceFile a boolean value of whether or not to replace a file if a file by the same specified name already exists in the destination folder.

Returns

Type Description
string A string of the one-time upload session url

global boolean morePagesAvailable()

See the documentation for getFolderContents for usage.

Returns

Type Description
boolean Returns true if more pages are available to continue the most recent query using getFolderContents.

global SharePointFileInfo moveItem(string itemId, string parentFolderId)

Move a file or folder and its descendants from one folder in SharePoint to another. Use this to have a Salesforce-triggered archive of files, for instance. An item can only be moved within its original document library. Use copyFile to place a file or folder in a different document library.

Parameters

Param Description
itemId The SharePoint id of the file or folder that is to be moved.
parentFolderId The SharePoint folder id to move the item to.

Returns

Type Description
SharePointFileInfo A SharePointFileInfo object of the file or folder that was moved.

global SharePointFileInfo renameFile(string fileId, string newName)

Changes the name of a file or folder in SharePoint

Parameters

Param Description
fileId The Id value from a SharePointFileInfo object
newName The item name with extension of the file to be renamed. Be sure to make sure that no illegal characters are in the fileName.

Returns

Type Description
SharePointFileInfo A SharePointFileInfo object of the file or folder that was renamed.

global SharepointFileInfo setupFolder(string recordId, string parentFolderId, string objectSettingsLabel)

This method mimics the UI button functionality: “Set Up in SharePoint”. Leverage this functionality to set up a folder for a given record exactly as is done in the UI. It will setup a folder according to the configuration of a specific SharePoint Object Settings record.
The method will:
• Create a folder for the record in the specified parent folder.
• Name the folder according to the field specified in SharePoint Object Settings.
• Set custom SharePoint fields on the new folder as specified in SharePoint Object Settings.
• Create the child folder hierarchy as specified in SharePoint Object Settings and set SharePoint custom fields on the newly created folders.
• Update the Salesforce record with the newly created SharePoint Folder Id.

Parameters

Param Description
recordId The Salesforce record id to create a folder for. It must correspond to the object type specified in the SharePoint Object Settings record
parentFolderId The SharePoint folder id in which to place the new folder. This can be populated from the SharePoint Object Settings record or set manually
objectSettingsLabel The label of the SharePoint Object Settings metadata record to use to set the folder up.

Returns

Type Description
SharepointFileInfo A SharePointFileInfo object of the folder that was setup.

global SharePointFileInfo updateCustomFields(string fileId, Map<String,String> customFields)

Manually sets custom field/value combinations to a document or folder in SharePoint
The example below shows how to set SharePoint custom text fields “SalesforceAccountId” to a hard-coded value and “Type” to a referenced account type.

Parameters

Param Description
fileId The Id value from a SharePointFileInfo object
customFields The format for the map is that the key is the SharePoint field name and the value is the value to write to that field.

Returns

Type Description
SharePointFileInfo A SharePointFileInfo object of the file or folder that was updated.

Example

Map<String,String> fields = new Map<String,String>();
    fields.put('SalesforceAccountId','001fusr7347f9setfUED');
    fields.put('Type',acct.Type);
    apiClient.updateCustomFields('sharepointFileId',fields);

global SharePointFileInfo uploadFile(string parentFolderId, string fileName, Blob fileContents)

A very simple upload method. This allows an upload of up to 4 MB and does not require a contentversion. This can be used to upload any blob as a file. Unlike other methods listed here, it does not set SharePoint fields automaticaly. Because of the 4 MB size limitation, uploadLargeFile is recommended.

Parameters

Param Description
parentFolderId Must be an existing folder within the Site and Document Library that the user has access to.
fileName The file name with extension of the file to be uploaded. Be sure to make sure that no illegal characters are in the fileName.
fileContents A blob value for the contents of the file.

Returns

Type Description
SharePointFileInfo A SharePointFileInfo object of the file that was uploaded.

Example

ContentVersion fileVersionToUpload : [SELECT Id, Title, FileExtension, VersionData, ContentDocumentId FROM ContentVersion WHERE ContentDocumentId = : ContentDocumentId LIMIT 1];
    Blob theBody;
    string fileName = '';
    theBody = fileVersionToUpload.VersionData;
    fileName = fileVersionToUpload.Title + '.' + fileVersionToUpload.FileExtension;
    apiClient.uploadFile(ParentFolderId, fileName,theBody);

global SharePointFileInfo uploadFile(string parentFolderId, string fileName, Blob fileContents, string recordId, map<string,string> customFields)

Upload that will also set SharePoint custom field values. This allows an upload of up to 4 MB and does not require a contentversion. This can be used to upload any blob as a file. The file will be uploaded, and upon completion, custom fields will be set in SharePoint.

Because of the 4 MB size limitation, uploadLargeFile is recommended.

Usage
The example below shows querying a contentversion by ContentDocumentId and uploading the file with custom SharePoint fields. It sets the SharePoint field, “SalesforceAccountId” to a hard-coded value and “Type” to a referenced account type.

Parameters

Param Description
parentFolderId Must be an existing folder within the Site and Document Library that the user has access to.
fileName The file name with extension of the file to be uploaded. Be sure to make sure that no illegal characters are in the fileName.
fileContents A blob value for the contents of the file
recordId This is the Salesforce Record ID that is associated with the file. It is required.
customFields The format for the map is that the key is the SharePoint field name and the value is the value to write to that field.

Returns

Type Description
SharePointFileInfo A SharePointFileInfo object of the file that was uploaded.

Example

ContentVersion fileVersionToUpload : [SELECT Id, Title, FileExtension, VersionData, ContentDocumentId FROM ContentVersion WHERE ContentDocumentId = : ContentDocumentId LIMIT 1];
    Blob theBody;
    string fileName = '';
    theBody = fileVersionToUpload.VersionData;
    fileName = fileVersionToUpload.Title + '.' + fileVersionToUpload.FileExtension;
    Map<String,String> fields = new Map<String,String>();
    fields.put('SalesforceAccountId','001fusr7347f9setfUED');
    fields.put('Type',acct.Type);
    apiClient.uploadFile(ParentFolderId, fileName,theBody,acct.Id,fields);

global SharePointFileInfo uploadLargeFile(string parentFolderId, string fileName, string documentVersionId)

Upload a file up to 11 MB but requires a ContentVersionId This method will not set SharePoint fields.

global SharePointFileInfo uploadLargeFile(string parentFolderId, string fileName, string documentVersionId, string recordId, map<string,string> customFields)

Upload up to 11 MB that will also set SharePoint custom field values.

global SharePointFileInfo uploadLargeFile(string parentFolderId, string fileName, string documentVersionId, string recordId, map<string,string> customFields, Boolean autodelete)

This signature allows the ability to retain the ContentVersion after the file is uploaded to SharePoint.

global SharePointFileInfo uploadLargeFile(string parentFolderId, string fileName, string documentVersionId, string recordId, map<string,string> customFields, Boolean autodelete, Boolean replaceFile)

Upload a file up to 11 MB but requires a ContentVersionId The file will be uploaded as a

Parameters

Param Description
parentFolderId Must be an existing folder within the Site and Document Library that the user has access to.
fileName The file name with extension of the file to be uploaded. Be sure to make sure that no illegal characters are in the fileName.
documentVersionId The ContentVersion Id of the file
recordId This is the Salesforce Record ID that is associated with the file. It is used by future methods to set custom fields on the record.
customFields The format for the map: the key is the SharePoint field name and the value is the value to write to that field.
autodelete (Optional) Boolean that determines whether ContentVersion created when uploading file to SharePoint is automatically deleted or not. Defaults to true (will automatically delete ContentVersion upon upload).
replaceFile (Optional) Boolean that determines whether the file uploaded will be replaced or renamed if another file with the same name exists.

Returns

Type Description
SharePointFileInfo A SharePointFileInfo object of the file that was uploaded.

Future method. Upon completion, custom fields will be set in SharePoint and a File_Uploaded_Community__e platform event will be fired. Code can be written to subscribe to the platform event to further extend functionality. All fields are required in order to set custom fields upon upload.

This method always returns null.


Usage
The example below shows querying a contentversion by ContentDocumentId and uploading the file with custom SharePoint fields. It sets the SharePoint field, “SalesforceAccountId” to a hard-coded value and “Type” to a referenced account type.

Example

for(ContentVersion fileVersionToUpload : [SELECT Id, Title, FileExtension, ContentDocumentId FROM ContentVersion WHERE ContentDocumentId = : ContentDocumentId LIMIT 1]){
    string fileName = '';
    fileName = fileVersionToUpload.Title + '.' + fileVersionToUpload.FileExtension;
    Map<string,string> fields = new Map<string,string>();
    fields.put('SalesforceAccountId','001fusr7347f9setfUED');
    fields.put('Type',acct.Type);
    apiClient.uploadLargeFile(ParentFolderId, fileName,fileVersionToUpload.Id,acct.Id,fields);}

global void writeDebugInfo()

This method will log sFiles Debug information in the sFiles Debug Log Object.
The following must be in place for this method to work:
• The log level in SharePoint Settings (Setup > Custom Metadata Types > SharePoint Setttings > Default) must be set to a value other than “None”.
• This method must be called after all sFiles methods and DML operations are complete.
• NOTE: Return the log level in step 1 to “None” when not in use to avoid unnecessary operations.


Classes

clientApiException

Inheritance

clientApiException