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 installation guide 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 automations 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 cloudfiles widget 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 platform event triggered flow we will create a platform triggered flow that will fire when a ' cloudfiles event ' message is received refer to the gif below for a visual understanding of this step we will add two decision outcomes here first, to copy the files from salesforce storage to external storage, and second, to delete the original files from the salesforce storage the details are discussed below, one by one copy uploaded files from salesforce storage to external storage ‘cloudfiles event’ messages can be generated for various events, we will first filter out the messages only for the event when a file is attached to the 'notes & attachment' of an account we will proceed to retrieve the details of the account’s connected folder and then copy the files from salesforce storage to that specific account folder 1 use ‘decision’ to filter event messages for files uploaded to salesforce start by adding a new “decision’ element add an outcome for file uploads in salesforce storage it will ask you to fill in certain parameters we will add 2 resources as given below 1 $record > object type equals account 2 $record > type equals “ salesforce file attached ” this is how the outcome detail looks like refer to the gif below to have a visual understanding of this step in order to get the account id of the account for which the file upload has happened, we will use two cloudfiles action “get events details’ and "get connected folder" 2 get event details using ‘get event details’ action to retrieve event details, we'll use the '' get event details " action, which provides various information about the event, including the account record id this id will be used in the next action in order to do so, add this action and select 'record' in the event dropdown menu this is how the action looks like 3 get account folder details using ‘get connected folder’ action previous action will return various outputs in order to get the folder id of the account folder, add ‘ get connected folder https //help cloudfiles io/salesforce/get connected folder flow action ’ in the parent id field, select ‘ salesforcefiles ’ > ‘ parentid’ refer to the gif below to have a visual understanding of this step once we have retrieved the account parent folder details, we will copy the files from salesforce to the external storage 4 copy the uploaded files to external storage using ‘copy salesforce files’ action we will use ‘ copy salesforce files ’ action to copy the file from salesforce storage to external storage like sharepoint, google drive etc once you add this action, it will ask you to fill in certain parameters as shown below 1 content document ids salesforce id of the uploaded file select salesforcefiles > contentdocumentids from the output of previous ‘get event details’ action 2 drive id drive id in external storage where file should be copied select driveid from the output of ‘get connected folder’ action 3 folder id id of the folder in external storage where the file should be copied to select driveid from the output of ‘get connected folder’ action select library from the output of ‘get connected folder’ action 4 library external storage type 5 salesforce record id id of the salesforce record where the original salesforce file is attached select ‘ salesforcefiles ’ > ‘ parentid ’ from the output of ‘get event details’ action this is how the action looks like refer to the gif below to have a visual understanding of this step delete files from the salesforce storage now that we have copied the files from salesforce storage to external storage, we will delete the originally uploaded files from the salesforce storage once the copy process is completed in order to do so, we will created another branch in the previous decision action as discussed in the next steps 1 use ‘decision’ to filter event messages for successful file copied start by adding a new outcome to previous decision element this is to determine if the file is copied from the salesforce storage to external storage it will ask you to fill in certain parameters we will add 1 resource here $record > type equals salesforce file copied this is how the outcome detail looks like refer to the gif below to have a visual understanding of this step 2 get copied files details using ‘get events details’ to retrieve copied file event details, we'll use the '' action again to get the content version id this id will be used in the next action in order to do so, add this action and select 'record' in the event dropdown menu this is how the action looks like 3 get content version of originally uploaded file using ‘get records’ to get the original file uploaded in salesforce storage, we will retrieve the content version , which represents a specific version of a document uploaded to a salesforce storage this is where the actual content of a file is stored to do so, we will add the 'get records' element we will add the object as ‘ content version ’ and we’ll add 1 resource below contentversion id equals salesforcefilecopied > contentversionid (you will get this from the output of previous get event details action) this is how it looks like refer to the gif below to have a visual understanding of this step 4 delete original file using ‘delete records’ action once we have retrieved the content version, we will proceed to delete the original document for this we will use content document which has been uploaded to salesforce storage add 'delete records' element select object as ‘ content document ’ and we’ll add 1 resource below contentdocument id equals contentdocumentid > (you will get this from the output of previous get records action) this is how the action looks like refer to the gif below to have a visual understanding of this step that’s it save and activate the flow! test the flow in action now that everything is setup, lets test our flow follow the steps below to move files from salesforce storage to account folder in external storage create a new account record in salesforce or go to an existing account record and upload a file in notes & attachment navigate to ‘files’ tab the flow may take a few seconds to run so click on the refresh icon on top right of the widget you should be able to see the uploaded file now navigate back to notes & attachment you should be able to see that the original file has been deleted congratulations! you've successfully moved files from salesforce storage to account folder in external storage