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
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 - e.g. /Accounts/ACME [0015I00000n0T3VQAU]/Opportunities/projectA
FOLDER = This represents the path relative to the base folder.
For Authenticated Access: The FOLDER variable is relative to the Record Folder.
Example:
To query a “file” in the Record Folder itself, set FOLDER to "file".
To query a “file” in a subfolder within the Record Folder, set FOLDER to "subfolder/file".
For Anonymous Access: The FOLDER variable is relative to the Public Folder, which is the default base folder for anonymous access. Files can only be uploaded to the Public Folder or its subfolders.
Additional info
Summary : 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.
So for Get File Link the FOLDER variable to query a “file” from the record folder would be “file” and if the file is located in a subfolder called “subfolder” , the variable would be "subfolder/file"
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();
uploadFile.recordId = RECORD_ID;
uploadFile.folderName = FOLDER;
uploadFile.contentId = CONTENT_ID; // accepts ContentVersion.Id, ContentDocument.Id, or Attachment.Id
uploadFile.isAnonymousAuth = USE_ANONYMOUS_AUTH;
uploadFile.deleteAfterUpload = DELETE_AFTER_UPLOAD; // set to true to remove from Salesforce after successful upload
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 public 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 public 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.
sfy_office365.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.
sfy_office365.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 List<List<Id>>{ new List<Id>{ RECORD_ID } };
List<List<sfy_office365.GetFolderPathResponse>> responses = sfy_office365.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.
sfy_office365.FilesMoveRequest req = new sfy_office365.FilesMoveRequest(PATH_from, PATH_to);
List<sfy_office365.FilesMoveRequest> requests = new List<sfy_office365.FilesMoveRequest>();
requests.add(req);
List<sfy_office365.X24FIlesSharepointMove.Response> responses = sfy_office365.X24FIlesSharepointMove.moveFolder(new List<List<sfy_office365.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.
sfy_office365.FileRemoveRequest req = new sfy_office365.FileRemoveRequest(RECORD_ID, FOLDER, USE_ANONYMOUS_AUTH);
List<sfy_office365.FileRemoveRequest> requests = new List<sfy_office365.FileRemoveRequest>();
requests.add(req);
List<sfy_office365.X24FIlesSharepointRemove.Response> responses = sfy_office365.X24FIlesSharepointRemove.removeFiles(new List<List<sfy_office365.FileRemoveRequest>> {requests})[0];
Remove Folders
Use this Apex method to remove a specified folder from SharePoint.
sfy_office365.FolderRemoveRequest req = new sfy_office365.FolderRemoveRequest(RECORD_ID,FOLDER, USE_ANONYMOUS_AUTH);
List<sfy_office365.FolderRemoveRequest> requests = new List<sfy_office365.FolderRemoveRequest>();
requests.add(req);
List<sfy_office365.X24FIlesSharepointRemoveFolder.Response> responses = sfy_office365.X24FIlesSharepointRemove.removeFolders(new List<List<sfy_office365.FolderRemoveRequest>> {requests})[0];
Upload Metadata
Use this Apex method to upload metadata to SharePoint.
List<sfy_office365.SharepointMetadata> metadata = new List<sfy_office365.SharepointMetadata>{new sfy_office365.SharepointMetadata(SHAREPOINT_FIELD, VALUE)};
sfy_office365.UploadMetadataRequest request = new sfy_office365.UploadMetadataRequest(RECORD_ID, filename,FOLDER,metadata);
List<sfy_office365.UploadMetadataRequest> innerList = new List<sfy_office365.UploadMetadataRequest>{ request };
List<List<sfy_office365.UploadMetadataRequest>> outerList = new List<List<sfy_office365.UploadMetadataRequest>>{ innerList };
sfy_office365.X24UploadMetadata.uploadMetadata(outerList);
Note that SharePoint does not allow to write all metadata via the Graph API. More specifically, the following metadata types are not supported:
Managed Metadata (Taxonomy): Single or multi-value managed metadata fields cannot be updated through standard Graph API calls.
Person/Group: Fields mapping to user profiles frequently fail to update.
URL/Hyperlink: Hyperlink structures are not supported for updates.
Lookup Fields: Complex lookup relationships cannot be updated.
This Apex action can also be used to Rename files. In order to do so, use the SHAREPOINT_FIELD FileLeafRef, make sure that the VALUE contains the file extension as well, else the file will become unusable. FileLeafRef is an internal SharePoint field name representing the file name (including extension) in document libraries.
Migrate Files Batch Upload
Use this Apex method to upload files in batch from Salesforce to SharePoint.
X24FilesMigrateBatch.FlowInput input = new X24FilesMigrateBatch.FlowInput(new List<Id>{RECORD_ID_1, RECORD_ID_2}, USE_ANONYMOUS_AUTH, DELETE_AFTER_UPLOAD, EMAIL_ADDRESS, FOLDER_PATH);
X24FilesMigrateBatch.uploadFiles(new List<X24FilesMigrateBatch.FlowInput>{input});
Create Chatter File Links
Use this Apex method to Create Chatter File Links. Please read the page Create Chatter File Links in the section Use 24Files with Flows for more background information.
sfy_office365.CreateJunctionChatterLinksRequest request = new sfy_office365.CreateJunctionChatterLinksRequest();
request.batchSize = 5;
request.reprocessAll = false;
List<sfy_office365.CreateJunctionChatterLinksRequest> requests = new List<sfy_office365.CreateJunctionChatterLinksRequest>();
requests.add(request);
List<sfy_office365.CreateJunctionChatterLinksResponse> responses = sfy_office365.CreateJunctionChatterLinksGlobalMethod.createChatterLinksForJunctions(requests);
Create Chatter File Links for a Record
This invocable Apex action automatically generates Chatter File Links for a Salesforce record by discovering files stored in corresponding SharePoint folders. It ensures that users see relevant SharePoint documents directly on the record’s Chatter feed without manual linking.
Inputs for this Apex action:
Record Id: the Salesforce record ID for which to generate Chatter file links.
Reprocess Chatter File Links: When
true,clears checkpoints and runs folder discovery again so new files in already-processed folders can get Chatter file links; existing path/External Id pairs are not duplicated.
How it works.
Resolves record type: uses the provided record id to determine the applicable 24Files Folder Structure(s); if multiple apply, uses the default structure.
Manages junctions: if no Folder Structure Junction exists, it creates the SharePoint/metadata path and junction record. Existing junctions are reused.
Reprocess behavior: when
Reprocess Chatter File Links = true, it resets the previously processed Chatter File Linkson the Folder Structure Junctions records and queues a full folder discovery (critical for new files added to previously processed folders).Discovers & upserts: finds files in SharePoint and upserts Chatter file link records (no duplicate links for existing paths/external IDs).
When to use it
Automatic generation of Chatter File Links without the need to manually visit the record page where the 24Files LWC is visible.
For synchronising new SharePoint file additions to Salesforce Chatter file links. Especially to fill in missing Chatter links for existing records or folder structures.
sfy_office365.CreateRecordChatterLinksRequest req = new sfy_office365.CreateRecordChatterLinksRequest();
req.recordId = RECORD_ID;
req.reprocessChatterLinks = REPROCESS_BOOLEAN;
List<sfy_office365.CreateRecordChatterLinksRequest> requests = new List<sfy_office365.CreateRecordChatterLinksRequest>();
requests.add(req);
List<sfy_office365.CreateRecordChatterLinksResponse> responses = sfy_office365.CreateRecordChatterLinks.createRecordChatterLinks(requests);
List All Files for a Record
This method gives your Flows or other Apex processes a way to see what’s in a folder without needing anyone to click around. It returns amongst others the number of files in a folder as well the name and size of the files. Please read the page List All Files for a Record in the section Use 24Files with Flows for more background information.
sfy_office365.X24FilesListFilesRequest request = new sfy_office365.X24FilesListFilesRequest();
request.recordId = '001...';
request.folderPath = '/subfolder';
request.useAnonymousAccess = false;
List<sfy_office365.X24FilesListFilesResponse> responses = sfy_office365.X24FilesListFiles.listFiles(
new List<sfy_office365.X24FilesListFilesRequest>{ request }
);