Skip to main content
Skip table of contents

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 = relative path to the file from the document library

Note that in case of Anonymous Authentication the PATH 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

CODE
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

CODE
sfy_office365.CreateFoldersGlobalMethod.createFolders(new List<sfy_office365.AddFolderGlobalMethod.FolderRequest>(), EMAIL_ADDRESS);

Create Folder Structure

CODE
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

CODE
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

CODE
sfy_office365.UploadFilesGlobalMethod.uploadFiles(new List<sfy_office365.AddFileGlobalMethod.FileRequest>(), EMAIL_ADDRESS);

Use this method to retrieve a link for a single file.

CODE
List<sfy_office365.GetFileLinksGlobalMethod.FileLinkRequest> fileLinkRequests = new List<sfy_office365.GetFileLinksGlobalMethod.FileLinkRequest>{new sfy_office365.GetFileLinksGlobalMethod.FileLinkRequest(RECORD_ID, PATH, USE_ANONYMOUS_AUTH)};
sfy_office365.GetFileLinksGlobalMethod.getFileLink(fileLinkRequests);

Use this method to retrieve links for a multiple files for multiple records.

CODE
List<sfy_office365.GetFileLinksGlobalMethodBatch.FileLinkRequestBatch> fileLinkRequestsBatch = new List<sfy_office365.GetFileLinksGlobalMethodBatch.FileLinkRequestBatch>
{
    new sfy_office365.GetFileLinksGlobalMethodBatch.FileLinkRequestBatch(
        RECORD_ID_1,
        PATH_1,
        USE_ANONYMOUS_AUTH
    ),
    new sfy_office365.GetFileLinksGlobalMethodBatch.FileLinkRequestBatch(
        RECORD_ID_2,
        PATH_2,
        USE_ANONYMOUS_AUTH
    ),
    new sfy_office365.GetFileLinksGlobalMethodBatch.FileLinkRequestBatch(
        RECORD_ID_3,
        PATH_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.

CODE
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.

CODE
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.

CODE
List<List<Id>> recordIds = new List<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.

CODE
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.

CODE
FileRemoveRequest req = new FileRemoveRequest(RECORD_ID, PATH, USE_ANONYMOUS_AUTH);
List<FileRemoveRequest> requests = new List<FileRemoveRequest>();
requests.add(req);
List<X24FIlesSharepointRemove.Response> responses = X24FIlesSharepointRemove.removeFiles(new List<List<FileRemoveRequest>> {requests})[0];

 Change Metadata

Use this Apex method to remove specified files from SharePoint, typically for scenarios where files need to be deleted based on Salesforce record information.

CODE
UploadMetadataRequest request = new UploadMetadataRequest(RECORD_ID, filename, path);
List<UploadMetadataRequest> innerList = new List<UploadMetadataRequest>{ request };
List<List<UploadMetadataRequest>> outerList = new List<List<UploadMetadataRequest>>{ innerList };
X24UploadMetadata.uploadMetadata(outerList);

 

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.