Tutorials
Document Management Tutorials
Automatically moving files from Salesforce storage to external storage
in this tutorial, we will demonstrate how to automatically move files uploaded to salesforce storage to an external storage system while deleting the originally uploaded files using salesforce cloudfiles integration we will utilize cloudfiles flow actions to facilitate the file movement process files in salesforce can come from a variety of source, for example from your document generation tool, e signature tool, email to case, or manual uploads by your users what to expect by the end of this tutorial, you can expect to copy the files uploaded in salesforce storage to account’s parent folder in external storage automatically automatically delete the original file stored in salesforce storage the gif below shows the expected output if you have a basic grasp of these concepts, you can expect to finish the tutorial in under 10 minutes our final setup involves a number of flow actions added to a salesforce flow as shown below in the sections below, we cover each of these actions and how to configure them 1 pre requisites before you start with the set up, please ensure these steps are completed install cloudfiles in salesforce cloudfiles is available on the salesforce appexchange and can be installed using the standard app installation process check out https //help cloudfiles io/salesforce/installation guide for cloudfiles salesforce integration to know more connect your cloud storage to salesforce using cloudfiles all automations in cloudfiles are activated through salesforce flow builder, utilizing account wide authentication for external storage libraries through a service (admin) user to connect your service user, access the setup, click on the external storage of choice and log into your account for detailed steps, follow https //help cloudfiles io/salesforce/automations or refer to the gif below for a clearer understanding add cloudfiles widget to account record to add the https //help cloudfiles io/salesforce/adding cloudfiles widgets to salesforce classic to the account record in salesforce, first, navigate to the account page and click on the "edit page" button once in the lightning builder, insert a new tab and drag and drop the "cloudfiles" widget onto the page save the changes and exit the builder refresh the salesforce record page, and the widget should now be visible, allowing easy access to view files and folders within salesforce 2 create a record triggered flow in this step, we will create a record triggered flow on the cloudfiles event custom object this flow is triggered whenever a cloudfiles event record is created and meets the defined entry conditions this flow will handle two key operations copying files from salesforce storage to external storage deleting the original files from salesforce storage after a successful copy refer to the gif below for a visual walkthrough of creating the record triggered flow and configuring the start conditions cloudfiles generates event records for multiple types of actions to ensure the flow runs only for relevant scenarios, we will configure entry criteria so the flow is triggered only when a cloudfiles event record is created the detailed handling of different event types—such as file uploads and file copy confirmations—is managed later in the flow using decision elements each event type is processed in a separate branch, which we will configure step by step in the following sections copy uploaded files from salesforce storage to external storage cloudfiles event records can be generated for a variety of actions in this section, we will focus on filtering events triggered when a file is attached to the notes & attachments section of an account when such an event is detected, the flow will retrieve the account’s connected folder in the external storage system, and copy the uploaded file from salesforce storage to the corresponding account folder in external storage in addition to handling file uploads, the flow also includes a second condition to detect successful file copy events this condition is used to initiate the cleanup process by deleting the original file from salesforce storage, ensuring that files are retained only in the external storage system these conditions are implemented using decision elements , with each outcome handled in a separate branch the configuration of each branch is explained step by step in the sections that follow 1 use a decision element to identify salesforce file attached events start by adding a decision element to the flow this element is used to filter cloudfiles event records and ensure that the flow proceeds only when a file is uploaded to salesforce storage create a new outcome specifically for file upload events and configure the condition as follows $record → type equals salesforce file attached this condition ensures that only events generated when a file is attached in salesforce are processed in this branch of the flow this is how the outcome details configuration looks once the file upload event is identified, we need to determine which account the file was uploaded to to retrieve the required account and folder information, we will use two cloudfiles actions docid\ cfegghvnwso7bcxyevrr docid iq8rljf2ne8sx0 iuu these actions allow us to extract the account id from the event and locate the corresponding account folder in external storage 2 get salesforce file attached event details using the get event details action to retrieve detailed information about the docid\ cnswhxyiaabekamvbfxon event, add the docid\ cfegghvnwso7bcxyevrr action to the flow this action provides key metadata related to the event, including the salesforce record id (account id) associated with the file upload this account id is required in the subsequent steps to locate the account’s connected folder in external storage when configuring the action add the get event details cloudfiles action in the event (custom object) placeholder, select triggering record refer to the gif below for a visual walkthrough of configuring the get event details action 3 get account folder details using the get connected folder action the previous step returns several outputs, including the salesforce record (account) id associated with the file upload event to locate the corresponding account folder in external storage, we will use the docid iq8rljf2ne8sx0 iuu action when configuring this action add the get connected folder cloudfiles action in the parent id field, select get file attached event details > salesforcefiles details → parentid this configuration allows cloudfiles to identify and retrieve the connected external storage folder associated with the account refer to the gif below for a visual walkthrough of configuring the get connected folder action once the account’s parent folder details are retrieved, we can proceed to copy the uploaded files from salesforce storage to the external storage system 4 copy uploaded files to external storage using the copy salesforce files action to copy files from salesforce storage to an external storage system (such as sharepoint , google drive , or other supported providers), we will use the docid\ xaoztzqon8utm7hyzn bg action add the copy salesforce files cloudfiles action to the flow and configure the following parameters content document ids specify the salesforce ids of the uploaded files select get file attached event details > salesforcefiles details → contentdocumentids from the output of the get event details action drive id identify the external storage drive where the file should be copied select driveid from the output of the get connected folder action folder id specify the target folder in the external storage system where the file should be copied select the appropriate folder id from the output of the get connected folder action library select the external storage provider (for example, sharepoint, google drive, etc ) salesforce record id specify the salesforce record to which the original file was attached select get file attached event details > salesforcefiles details → parentid from the output of the get event details action this configuration ensures that the uploaded file is copied to the correct account folder in external storage and remains properly associated with the salesforce record this is how the copy salesforce files action is configured in the flow refer to the gif below for a visual walkthrough of this step delete files from the salesforce storage once the files have been successfully copied from salesforce storage to the external storage system, the final step is to delete the original files from salesforce storage this ensures that files are retained only in external storage, helping reduce salesforce storage usage to achieve this, we will add another branch to the existing decision element in the flow this branch will handle events that confirm a successful file copy and will initiate the deletion process the detailed configuration of this branch is covered in the steps that follow 1 use a decision element to identify successful file copy events add a new outcome to the existing decision element to determine when a file has been successfully copied from salesforce storage to external storage configure the outcome with the following condition $record → type equals salesforce file copied this condition ensures that the flow proceeds only after cloudfiles confirms that the file copy operation has completed successfully this is how the outcome details configuration looks 2 get copied file event details using the get event details action to retrieve details of the docid\ m9v6ikaxwsmxifd5e7zwy event, add the docid\ cfegghvnwso7bcxyevrr action to the flow this action provides information related to the copied file, including the content version id , which is required for identifying and deleting the original file in salesforce storage when configuring this action add the get event details cloudfiles action in the event (custom object) dropdown, select triggering record this is how the get event details action is configured in the flow 3 get the content version of the original salesforce file using get records to identify the original file uploaded to salesforce storage, we need to retrieve its content version record a content version represents a specific version of a file stored in salesforce and contains the reference required to delete the associated document to do this, add a get records element to the flow and configure it as follows object contentversion condition contentversionid equals get file copied event details > salesforcefilecopied → contentversionid (this value is obtained from the output of the previous get file copied event details action ) this configuration allows the flow to locate the correct content version associated with the copied file refer to the gif below for a visual walkthrough of configuring the get records element 4 delete original file using ‘delete records’ action once the content version of the original file has been retrieved, the final step is to delete the corresponding content document from salesforce storage to do this, add a delete records element to the flow and configure it as follows object contentdocument condition contentdocumentid equals get content version > contentdocumentid (this value is obtained from the output of the previous get records action ) this step permanently removes the original file from salesforce storage after it has been successfully copied to external storage refer to the gif below for a visual walkthrough of configuring the delete records element that’s it! save and activate the flow to complete the setup test the flow in action now that the setup is complete, let’s test the flow to verify that files are automatically moved from salesforce storage to the account folder in external storage follow the steps below to validate the configuration upload a file to an account create a new account record or open an existing one upload a file in the notes & attachments section verify the file in external storage navigate to the files tab the flow may take a few seconds to execute, so click the refresh icon in the top right corner of the cloudfiles widget if needed confirm that the uploaded file appears in the account’s folder in external storage confirm deletion from salesforce storage navigate back to notes & attachments verify that the original file has been removed from salesforce storage congratulations! you’ve successfully configured the automation to move files from salesforce storage to the corresponding account folder in external storage