24Files Apex methods
Parameters
The following capitalized items need to be replaced by your specific values when calling the 24Files Apex methods:
RECORD_ID = ID of the record
FOLDER = relative folder to the record folder. Note: in case of anonymous access, you can only upload in the public folder and this folder is the standard relative path for anonymous access.
USE_ANONYMOUS_AUTH = set to ‘true’ to use anonymous auth or ‘false’ to use authenticated auth
EMAIL_ADDRESS = email address where results should be sent to
CONTENT_VERSION_ID = Salesforce content version id where the file is stored in
PATH = long path including the document library e.g. /Shared Documents/Accounts/ACME [0015I00000n0T3VQAU]/Opportunities/projectA
Note that in case of Anonymous Authentication the FOLDER is the path relative from the Public Folder. For Authenticated Authentication, this is the path relative from the Record Folder.
Limitations
With APEX, file uploads are limited to a maximum size of 35 MB per file.
The getFileLink APEX method returns a link with an expiration duration that has been set in the 24Files Settings page in the 24Files Manager app.
Create Single Folder
sfy_office365.AddFolderGlobalMethod.FolderRequest folderRequest = new sfy_office365.AddFolderGlobalMethod.FolderRequest(RECORD_ID, FOLDER, USE_ANONYMOUS_AUTH);
sfy_office365.CreateFoldersGlobalMethod.createFolder(folderRequest, EMAIL_ADDRESS);
Create Multiple Folders
sfy_office365.CreateFoldersGlobalMethod.createFolders(new List<sfy_office365.AddFolderGlobalMethod.FolderRequest>(), EMAIL_ADDRESS);
Create Folder Structure
List<sfy_office365.GenerateFolderStructureGlobalMethod.FolderStructureRequest> generateFolderStructures = new List<sfy_office365.GenerateFolderStructureGlobalMethod.FolderStructureRequest>{new sfy_office365.GenerateFolderStructureGlobalMethod.FolderStructureRequest(RECORD_ID, USE_ANONYMOUS_AUTH, EMAIL_ADDRESS)};
sfy_office365.GenerateFolderStructureGlobalMethod.generateFolderStructure(generateFolderStructures);
Upload File
sfy_office365.AddFileGlobalMethod.FileRequest uploadFile = new sfy_office365.AddFileGlobalMethod.FileRequest(RECORD_ID, FOLDER, CONTENT_VERSION_ID, USE_ANONYMOUS_AUTH);
sfy_office365.UploadFilesGlobalMethod.uploadFile(uploadFile, EMAIL_ADDRESS);
Upload Files
sfy_office365.UploadFilesGlobalMethod.uploadFiles(new List<sfy_office365.AddFileGlobalMethod.FileRequest>(), EMAIL_ADDRESS);
Get File Link
Use this method to retrieve a link for a single file.
List<sfy_office365.GetFileLinksGlobalMethod.FileLinkRequest> fileLinkRequests = new List<sfy_office365.GetFileLinksGlobalMethod.FileLinkRequest>{new sfy_office365.GetFileLinksGlobalMethod.FileLinkRequest(RECORD_ID,FOLDER, USE_ANONYMOUS_AUTH)};
sfy_office365.GetFileLinksGlobalMethod.getFileLink(fileLinkRequests);
Get File Links
Use this method to retrieve links for a multiple files for multiple records.
List<sfy_office365.GetFileLinksGlobalMethodBatch.FileLinkRequestBatch> fileLinkRequestsBatch = new List<sfy_office365.GetFileLinksGlobalMethodBatch.FileLinkRequestBatch>
{
new sfy_office365.GetFileLinksGlobalMethodBatch.FileLinkRequestBatch(
RECORD_ID_1,
FOLDER_1,
USE_ANONYMOUS_AUTH
),
new sfy_office365.GetFileLinksGlobalMethodBatch.FileLinkRequestBatch(
RECORD_ID_2,
FOLDER_2,
USE_ANONYMOUS_AUTH
),
new sfy_office365.GetFileLinksGlobalMethodBatch.FileLinkRequestBatch(
RECORD_ID_3,
FOLDER_3,
USE_ANONYMOUS_AUTH
)
};
sfy_office365.GetFileLinksGlobalMethodBatch.getFileLinkBatch(fileLinkRequestsBatch);
Metadata Sync
24Files allows you to sync Salesforce fields to SharePoint metadata at the time when a new record is created. Use this Apex method to enable a sync at other times, e.g. when records fields are updated.
X24FilesMetadataSync.metadataSync(List<String> recordIds);
Rename Record Folder
Use this Apex method to rename the record folder in SharePoint, e.g. triggered by a change of the record folder name in Salesforce.
X24FilesRenameRecordFolder.renameRecordFolders(List<String> recordIds);
Get Folder Path
Use this Apex method to retrieve the folder paths for specified records in SharePoint, typically as part of integrations or automations involving SharePoint folder structures.
List<List<Id>> recordIds = new Lidost<List<Id>>{ new List<Id>{ RECORD_ID } };
List<List<GetFolderPathResponse>> responses = X24FilesSharepointGetFolderPath.getFolderPath(recordIds);
Move Folder
Use this Apex method to move folders within SharePoint by specifying the old and new paths. This method can be utilized as part of an automation process where folder paths need to be updated.
FilesMoveRequest req = new FilesMoveRequest(PATH_from, PATH_to);
List<FilesMoveRequest> requests = new List<FilesMoveRequest>();
requests.add(req);
List<X24FIlesSharepointMove.Response> responses = X24FIlesSharepointMove.moveFolder(new List<List<FilesMoveRequest>> {requests})[0];
Remove Files
Use this Apex method to remove specified files from SharePoint, typically for scenarios where files need to be deleted based on Salesforce record information.
FileRemoveRequest req = new FileRemoveRequest(RECORD_ID, FOLDER, USE_ANONYMOUS_AUTH);
List<FileRemoveRequest> requests = new List<FileRemoveRequest>();
requests.add(req);
List<X24FIlesSharepointRemove.Response> responses = X24FIlesSharepointRemove.removeFiles(new List<List<FileRemoveRequest>> {requests})[0];
Remove Folders
Use this Apex method to remove a specified folder from SharePoint.
FolderRemoveRequest req = new FolderRemoveRequest(RECORD_ID,FOLDER, USE_ANONYMOUS_AUTH);
List<FolderRemoveRequest> requests = new List<FolderRemoveRequest>();
requests.add(req);
List<X24FIlesSharepointRemoveFolder.Response> responses = X24FIlesSharepointRemove.removeFolders(new List<List<FolderRemoveRequest>> {requests})[0];
Upload Metadata
Use this Apex method to upload metadata to SharePoint.
List<SharepointMetadata> metadata = new List<SharepointMetadata>{new SharepointMetadata(SHAREPOINT_FIELD, VALUE)};
UploadMetadataRequest request = new UploadMetadataRequest(RECORD_ID, filename,FOLDER,metadata);
List<UploadMetadataRequest> innerList = new List<UploadMetadataRequest>{ request };
List<List<UploadMetadataRequest>> outerList = new List<List<UploadMetadataRequest>>{ innerList };
X24UploadMetadata.uploadMetadata(outerList);