Toolkit Details
Class Name:box.Toolkit
Instance Variables
mostRecentError
String to indicate the most recent error that occurred when calling instance
methods.
The presence of this string does not mean the operation did not succeed. It is
possible the error was recoverable; however, the lack of a value in this string
does indicate the operation was successful.
Enum CollaborationType
Enum to indicate the type of collaboration.
Possible values: EDITOR, VIEWER, PREVIEWER, UPLOADER, COOWNER,
OWNER, PREVIEWERUPLOADER, or VIEWERUPLOADER
Static Methods
deleteServiceUserAssociation
Method to clear association between Service Account and Box for Salesforce
integration. This can be used to change the service account if an incorrect one
is being used.
Parameters:
- None
trueif the user’s account existed and was deleted.falseif the user’s account was not deleted for any reason (including because it didn’t exist).
deleteUserAssociation
Returns:
trueif the user’s account existed and was deleted.falseif the user’s account was not deleted for any reason (including because it didn’t exist).
Instance Methods - Constructors, Destructors
box.Toolkit()
Parameters:
- None
commitChanges
Treat this method as a destructor for the box.Toolkit() method.
Since Salesforce doesn’t allow callouts after database updates / inserts /
deletes have occurred, the Toolkit class maintains some collections of objects
to be inserted once all callout operations are complete. If this method is not
called, those objects won’t be in the database, and the tables that keep track
of user / record / folder associations will be out of sync and will need some
advanced debugging to fix.
Parameters:
- None
Void
commitChanges with platform event
Treat this method as a destructor for the box.Toolkit() method.
This method is very similar to the commitChanges above. However, it uses
a platform event to commit changes to the database to perform DML statements
in a different transaction and avoid governor limits in some scenarios.
Returns:
Void
Generic Methods
The Box for Salesforce Developer Toolkit provides a global method that accepts an HttpRequest object as a parameter and returns an HttpResponse object. This method uses the authentication details of the Service Account to make callouts to Box’s APIs, allowing you to focus on the business logic of your integration.sendRequest
Returns:
- An HttpResponse object with the response details from calling Box’s APIs.
Toolkit.BoxApiExceptionif there is any missing information from the HttpRequest input.nullif there was an issue getting the authentication details for the Service Account. In this case, checkmostRecentError.
File Operations
createFileFromAttachment
Available in version 3.46 and above.Salesforce has a String length limit of 6 million characters. Due to string
bloat in the base64 encoding/decoding process, this results in an effective
file size limit of 4.3 megabytes for synchronous Apex and 8.6 megabytes for
asynchronous Apex.
Returns:
stringreturned is the ID of the Box file that was created.nullif there was an error. In this case, checkmostRecentError.
pushFileToBox
Uploads a Salesforce Files ContentVersion record to a Box folder.
Returns:
PartnerSyncResponseobject with the upload details.nullif the upload fails. In this case, checkmostRecentError.
- This method uses service account authentication.
- It validates that the
ContentVersionexists before attempting the upload. - It checks the file size before upload so unsupported files fail early.
- Box API and rate-limit errors are surfaced through
mostRecentError. - Check
mostRecentErrorwhen the method returnsnull.
createFileShareLink
Creates a shared link for a Box file.
Returns:
stringreturned is the shared link URL.nullif the shared link is not created. In this case, checkmostRecentError.
- This method uses service account authentication.
- It creates the shared link with the default Box permissions.
- Check
mostRecentErrorwhen the method returnsnull.
moveFile
Moves a Box file to a different folder.
Returns:
Fileobject with the updated parent folder.- If the move fails, the returned
Fileobject can include astatusvalue. CheckmostRecentErrorfor details.
- If
accessTokenis blank ornull, the method uses service account credentials. - Check the returned
Fileobject’sstatusvalue for operation errors. - Check
mostRecentErrorif the operation fails.
Folder Operations
getRootFolderId
Parameters:
- None
stringreturned is the Box folder ID of the Salesforce root folder.
getObjectFolderByRecordId
Returns:
stringreturned is the Box folder ID of the object root folder for the record ID passed in.
getFolderUrl
- This method gets the embed widget URL for a particular record so customers can use their own embed logic if desired.
- This method respects seamless login settings so the URL will automatically log the user in if seamless login is enabled.
Returns:
stringreturned is a URL that points to the folder associated with the Salesforce record ID passed. This URL is for the Box Embed Widget and can be embedded in any Visualforce page.
createObjectFolderForRecordId
Returns:
stringreturned is the Box folder ID of the root folder that was created.- If the root folder already existed, the value returned is the Box folder ID of the root folder that already existed.
createFolder
Returns:
stringreturned is the Box folder ID of the folder that was created.nullis returned if a folder is not created. In this case, checkmostRecentErrorfor details.
createFolderShareLink
Creates a shared link for a Box folder.
Returns:
stringreturned is the shared link URL.nullif the shared link is not created. In this case, checkmostRecentError.
- This method uses service account authentication.
- It creates the shared link with the default Box permissions.
- Check
mostRecentErrorwhen the method returnsnull.
getFolderContents
Retrieves files and subfolders from a Box folder.
Returns:
FolderContentsobject containing the files and folders in the Box folder.- If the request fails, the returned
FolderContentsobject can include astatusvalue. CheckmostRecentErrorfor details.
- If
accessTokenis blank ornull, the method uses service account credentials. - The response can include both files and subfolders.
- Check the returned
FolderContentsobject’sstatusvalue for operation errors. - Check
mostRecentErrorif the operation fails.
createFolderForRecordId
Returns:
stringreturned is the Box folder ID of the folder that was created.nullis returned if a folder is not created. In this case, checkmostRecentErrorfor details.- If the Salesforce record was already associated with a Box folder, the existing Box folder ID is returned.
moveFolder
Returns:
trueif the folder was moved successfully.falseif the folder was not moved successfully. CheckmostRecentErrorfor details.
getUrlForFolder
Returns:
pageReferenceobject with provided URL.nullif the parameters are incorrect.
createFolderForRecordIdFromTemplate
Returns:
- Newly created folder ID.
nullif the parameters are incorrect.
Folder Association Methods
getFolderAssociationsByRecordId
Returns:
- List returned is a collection of all folder mapping entries associated with this record.
- Generally, it will be an empty list if no folder mapping entries exist, but under some circumstances, it could be
null.
getFolderIdByRecordId
Returns:
stringreturned is the Box folder ID associated with the Salesforce record ID passed in.
getFolderIdsByRecordIds
Retrieves Box folder IDs associated with one or more Salesforce record IDs.
Returns:
Map<Id, String>where each key is a Salesforce record ID and each value is the associated Box folder ID.- An empty map if no folder associations exist.
- This method queries Salesforce folder associations and does not call the Box API.
- It queries the
Record_ID_Indexed__cfield on theFRUP__cobject. - It returns only associations where
Box_Folder_ID__chas a value. - Use this method to look up multiple record-to-folder associations in one call.
getRecordIdByFolderId
Returns:
idreturned is the Salesforce record ID associated with the Box folder ID passed in.
createFolderAssociation
Returns:
box__FRUP__cobject - The FRUP object returned will benullif there was an error (checkmostRecentError). Upon calling thecommitChangesmethod, this FRUP entry will be inserted into the database. This method ensures consistency with other folder associations by not allowing the same folder to be associated with multiple records or vice versa.
Collaboration Methods
createCollaboration
Returns:
stringreturned is the ID of the Box collaboration that was created.nullreturned if there was an error. In this case, checkmostRecentError.
createCollaborationOnRecord
Returns:
stringreturned is the ID of the Box collaboration that was created.nullreturned if there was an error. In this case, checkmostRecentError.
editCollaboration
Returns:
- Boolean based on the transaction success.
falseif the parameters are incorrect.
deleteCollaboration
Returns:
- Boolean based on the transaction success.
falseif the parameters are incorrect.
Search and Discovery
search
Searches Box content accessible to the service account.
Returns:
SearchResultsobject with matching files and folders.nullif the search fails. In this case, checkmostRecentError.
- This method uses service account authentication.
- It searches file names, descriptions, and content accessible to the service account.
- Box returns up to 100 results by default.
- Use
searchwith filters when you need pagination or narrower search scope. - Check
mostRecentErrorwhen the method returnsnull.
search with filters
Searches Box content with filtering, pagination, and scope controls.
Returns:
SearchResultsobject with matching files and folders.nullif the search fails. In this case, checkmostRecentError.
- This method uses service account authentication.
- Use
scopeto choose between user content and enterprise content. - The Box API supports up to 200 results per request.
- Use
offsetto paginate through larger result sets. - Use
ancestorFolderIdsto limit results to specific folder hierarchies. - Check
mostRecentErrorwhen the method returnsnull.
getRecentInteractions
Retrieves files and folders recently interacted with by the current user.
Parameters:
- None
RecentItemsobject containing recently accessed content.nullif the request fails. In this case, checkmostRecentError.
- This method uses service account authentication.
- Results are returned in order of most recent interaction.
- Interactions can include actions such as opening, previewing, downloading, or editing an item.
- Box limits the response to the API default, typically 100 items.
- Check
mostRecentErrorwhen the method returnsnull.
Enterprise Events
getEnterpriseEvents
Retrieves enterprise events for auditing and monitoring Box activity.
Returns:
EnterpriseEventsobject with event entries and the next stream position.nullif the request fails. In this case, checkmostRecentError.
- This method uses service account authentication and requires enterprise admin privileges.
- Use the
streamPositionfrom the previous response to continue polling the event stream. - The Box API supports up to 500 events per request.
- Date filters must use ISO 8601 format, such as
YYYY-MM-DDTHH:MM:SSZ. - Check
mostRecentErrorwhen the method returnsnull.
Metadata
Check the
toolkit.mostRecentError value for detailed error responses
for all the methods.getMetadataTemplateByName
Retrieves a metadata template definition by name and scope.
Returns:
MetadataTemplateobject with the template definition.nullif the template is not retrieved. In this case, checkmostRecentError.
- This method uses service account authentication.
- Use it to inspect or validate a metadata template before creating or updating metadata values.
- Check
mostRecentErrorwhen the method returnsnull.
getBoxMetadataByFileId
This method calls the .
Returns:
Metadataobject with the metadata key/value pairs.nullif the metadata is not retrieved. In this case, checkmostRecentError.
- This method uses service account authentication.
- The request returns an error if the metadata instance does not exist on the file.
- Check
mostRecentErrorwhen the method returnsnull.
createBoxMetadataByFileId
This method calls the .
Returns:
Metadataobject with the created metadata values.nullif the metadata is not created. In this case, checkmostRecentError.
- This method uses service account authentication.
- The method fails if metadata already exists for the specified file, scope, and template. Use
updateBoxMetadataByFileIdto modify existing metadata. - Metadata keys must match the template field names.
- Check
mostRecentErrorwhen the method returnsnull.
updateBoxMetadataByFileId
This method calls the .
Returns:
Metadataobject with the updated metadata values.nullif the metadata is not updated. In this case, checkmostRecentError.
- This method uses service account authentication.
- The
operationsparameter uses JSON Patch format. - Each operation should include an
op,path, and, when required by the operation, avalue. - Supported operations include
add,replace,remove, andtest. - Check
mostRecentErrorwhen the method returnsnull.
deleteBoxMetadataByFileId
This method calls the .
Returns:
- Boolean based on the transaction success.
falseif the metadata is not deleted. In this case, checkmostRecentError.
- This method uses service account authentication.
- It deletes the metadata instance from the file. It does not delete the metadata template.
- Check
mostRecentErrorwhen the method returnsfalse.
getBoxMetadataByFolderId
This method calls the .
Returns:
FolderMetadatarecord associated with this folder, scope, and template key. You can find the custom values inkeyValuePairsvariable of this object.null, if:- the parameters are incorrect,
- access to the folder is missing,
- metadata cascade policy is not found.
createBoxMetadataByFolderId
This method calls the endpoint.
Returns:
- Newly created
FolderMetadataobject. null, if:- the parameters are incorrect,
- access to the folder is missing,
- metadata cascade policy is not found.
updateBoxMetadataByFolderId
Calls the endpoint.
Returns:
- Updated
FolderMetadataobject. null, if:- the parameters are incorrect,
- access to the folder is missing,
- metadata cascade policy is not found.
deleteBoxMetadataFolderId
This method calls the endpoint.
Returns:
- Boolean based on the transaction success.
falseis returned if the parameters are incorrect or the metadata is not found.
getMetadataCascadePolicyById
This method calls the
endpoint. As it requires an ID, you need to call the
getMetadataCascadePoliciesByFolderId method first.
Returns:
MetadataCascadePolicyobject retrieved from Box.null, if:- the parameters are incorrect,
- access to the folder is missing,
- metadata cascade policy is not found.
getMetadataCascadePoliciesByFolderId
This method retrieves the cascade policies by providing a folder ID and
calling the endpoint.
Returns:
- List of
MetadataCascadePolicyobjects retrieved from Box. null, if:- the parameters are incorrect,
- access to the folder is missing,
- metadata cascade policy is not found.
createMetadataCascadePolicy
This method creates cascade policies by providing a Box folder ID, scope,
template key, and by calling the endpoint.
Returns:
- Newly generated
MetadataCascadePolicy. null, if:- the parameters are incorrect,
- access to the folder is missing,
- metadata cascade policy details are not found.
deleteMetadataCascadePolicy
This method deletes the cascade policies by providing a cascade policy
ID and calling the endpoint.
Returns:
- Boolean based on the transaction success.
falseis returned if parameters are incorrect, access to the folder is missing, or the metadata cascade policy is not found.
enableAppActivity
This method enables the given folder for App Activities by applying
metadata on the folder and cascading it down.
Returns:
- Boolean based on the transaction success.
falsein case of incorrect parameters.
Salesforce and Slack
getIntegrationMappings
This toolkit method calls the endpoint to get the
existing mappings.
Returns:
- A list of
IntegrationMappingobjects. nullis returned if the parameters are incorrect, the access is missing, or the integration mapping is not found.
createIntegrationMapping
This toolkit method calls the endpoint to create
the mappings.
When you map to a Slack channel,
access_management_disabled is set to FALSE by default.
This causes an automatic removal of collaborators that are not part
of the Slack channel member list. Depending on how your organization
sets up sharing in Box, we recommend that you either set
access_management_disabled to TRUE by using the
setSlackChannelAccessManagementDisabled method, or use groups.
This ensures no users are removed, regardless of Slack settings.
Collaborations are added or removed from Slack when a file is uploaded
to a Slack channel.
Returns:
- Boolean based on the transaction success.
deleteIntegrationMapping
This toolkit method calls the endpoint to
delete a mapping.
Returns:
- Boolean based on the transaction success.
mapSfdcRecordToSlackChannel
This toolkit method uses the above integration mapping methods and
provides a wrapper with four different use cases:
- If a mapping does not exist in Salesforce or Slack, it creates a folder under the Box for Salesforce folder structure, and an integration mapping to link it with the Slack channel.
- If a mapping only exists from Salesforce, it continues to use the folder and does not change the location. It creates an integration mapping to link it with the Slack channel.
- If a mapping only exists from Slack, it continues to use the folder and creates an FRUP record for the Salesforce record to use the existing folder. This folder is likely to be outside of the Salesforce root folder.
- If Salesforce and Slack have existing mappings but are not related to each other, it throws an error through
Toolkit.mostRecentErroror within a flow action, stating that the mappings already exist.
Create Box Folder/Slack Channel Mapping.
When you map to a Slack channel,
access_management_disabled is set to FALSE by default.
This causes an automatic removal of collaborators that are not part
of the Slack channel member list. Depending on how your organization
sets up sharing in Box, we recommend that you either set
access_management_disabled to TRUE by using the
setSlackChannelAccessManagementDisabled method, or use groups.
This ensures no users are removed, regardless of Slack settings.
Collaborations are added or removed from Slack when a file is uploaded
to a Slack channel.
Returns:
- Boolean based on the transaction success.
setSlackChannelAccessManagementDisabled
This toolkit method calls the endpoint to update
the access management deactivated setting.
This method/invocable is used in a flow template provided in the Box
for Salesforce package Create Box Folder/Slack Channel Mapping.
Returns:
- Boolean based on the transaction success.
Box Sign
sendSignRequests
This method calls the endpoint to send documents for signature.
Returns:
List of
BoxSignResponse objects, one for each request processed. Each response contains the sign request ID, status, and any error information.
BoxSignResponse returns error details, if:
- the parameters are incorrect,
- access to the files is missing,
- file upload fails,
- Box Sign API returns an error.
Document Generation
submitDocGenBatch
Submits a batch of documents to generate from a Box document generation template.
Returns:
DocGenBatchobject with the batch ID and status.nullif the batch is not submitted. In this case, checkmostRecentError.
- This method uses service account authentication.
- Each document configuration should include the generated file name and the merge data for the template, such as
fileNameanddatavalues. - Document generation runs asynchronously. Use
getDocGenBatchto check the batch status. - Check
mostRecentErrorwhen the method returnsnull.
getDocGenBatch
Retrieves the status and details of a document generation batch.
Returns:
DocGenBatchobject with the batch status and generated file details.nullif the batch is not retrieved. In this case, checkmostRecentError.
- This method uses service account authentication.
- Poll this method periodically to monitor batch progress.
- Batch statuses include
pending,processing,completed, andfailed. - Generated file details are available after the batch is complete.
- Check
mostRecentErrorwhen the method returnsnull.
File Requests
copyFileRequest
Creates a copy of an existing file request with customizable properties.
Returns:
FileRequestobject with the new file request details.nullif the file request is not copied. In this case, checkmostRecentError.
- This method uses service account authentication.
- If optional parameters are
null, the new file request inherits those values from the source file request. - Use
activeto enable the copied file request immediately. - Check
mostRecentErrorwhen the method returnsnull.
copyFileRequest with default settings
Creates a copy of an existing file request using the source file request settings and a new destination folder.
Returns:
FileRequestobject with the new file request details.nullif the file request is not copied. In this case, checkmostRecentError.
- This method uses service account authentication.
- The copied file request inherits settings from the source file request and uses the folder ID you provide.
- Use this method when you only need to change the destination folder.
- Check
mostRecentErrorwhen the method returnsnull.
Box Hubs
Manage Box Hubs
getHubById
This method calls the endpoint to retrieve a specific hub.
Returns:
- Hub object containing the hub details and metadata.
HubsToolkitExceptionif:- the hub ID is blank or null,
- access to the hub is missing,
- the hub is not found.
getAllHubs
This method calls the endpoint to retrieve a list of all hubs.
Returns:
HubsListobject containing the list of hubs and pagination information.HubsToolkitExceptionif:- access to hubs is missing,
- API request fails.
getEnterpriseHubs
This method calls the endpoint to retrieve enterprise-level hubs.
Returns:
HubsListobject containing the list of enterprise hubs and pagination information.HubsToolkitExceptionif:- access to enterprise hubs is missing,
- API request fails.
createHub
This method calls the to create a new hub.
Returns:
- Hub object containing the newly created hub details.
HubsToolkitExceptionif:- the title is blank or null,
- the title exceeds 50 characters,
- access to create hubs is missing,
- API request fails.
updateHub
This method calls the to modify an existing hub.
Returns:
- Hub object containing the updated hub details.
HubsToolkitExceptionif:- the hub ID is blank or null,
- the update request is null,
- the title exceeds 50 characters,
- access to the hub is missing,
- API request fails.
copyHub
This method calls the to create a copy of an existing hub.
Returns:
- Hub object containing the newly created copied hub details.
HubsToolkitExceptionif:- the hub ID is blank or null,
- the title exceeds 50 characters,
- access to the source hub is missing,
- API request fails.
Box Hub Collaborations
createUserCollaboration
This method calls the endpoint to add a user to a hub.
Returns:
HubCollaborationobject containing the collaboration details.HubsToolkitExceptionif:- the hub ID is blank or null,
- the user ID is blank or null,
- the role is blank or null,
- access to the hub is missing,
- API request fails.
createHubCollaboration
This method calls the endpoint to add a collaboration to a hub.
Returns:
HubCollaborationobject containing the collaboration details.HubsToolkitExceptionif:- the collaboration request is null,
- the hub reference with ID is missing,
- access to the hub is missing,
- API request fails.
getHubCollaborations
This method calls the endpoint to retrieve collaborations for a hub.
Returns:
HubCollaborationsListobject containing the list of collaborations and pagination information.HubsToolkitExceptionif:- the hub ID is blank or null,
- access to the hub is missing,
- API request fails.
updateHubCollaboration
This method calls the endpoint to modify a collaboration.
Returns:
HubCollaborationobject containing the updated collaboration details.HubsToolkitExceptionif:- the collaboration ID is blank or null,
- the role is blank or null,
- access to the collaboration is missing,
- API request fails.
Box Hub Items
addHubItem
This method calls the endpoint to add an item to a hub.
Returns:
HubItemsManageResponseobject containing the result of the item management operation.HubsToolkitExceptionif:- the hub ID is blank or null,
- the item ID is blank or null,
- the item type is blank or null,
- access to the hub is missing,
- API request fails.
Debugging
setEnhancedDebugging
Enables or disables enhanced debug logging for the current Toolkit instance.
Returns:
Void
- Enhanced debugging applies only to the current Toolkit instance.
- When enabled, enhanced debugging logs additional HTTP request and response details.
- Use enhanced debugging for troubleshooting, and disable it in production to avoid unnecessary logging.
- The setting does not persist across transactions.
isEnhancedDebuggingEnabled
Checks whether enhanced debugging is enabled for the current Toolkit instance.
Parameters:
- None
trueif enhanced debugging is enabled.falseif enhanced debugging is disabled.
- This method has no side effects.
- Use it to conditionally run debug-only logic.
- The returned value reflects the setting applied by
setEnhancedDebugging.
