Tutorials
Document Management Tutorials

Automated nested folders creation based on object relationships

in this tutorial, we'll automate nested folders creation in any external storage system based on object relationships using cloudfiles salesforce integration as an example, we'll demonstrate how to generate nested ‘opportunities’ folders within associated ‘account’ folder when new opportunities are created we will use cloudfiles flow actions to create these nested folders what to expect by the end of this tutorial, you can expect to have an automated account folder and opportunities sub folder created when a new account is created have nested folders for newly created opportunities within the associated account's opportunities sub folder you will be able to attach these folders and sub folders to your record and will also be able to access these folders within your salesforce record within cloudfiles widget 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 tutorial video refer to the quick video if you would like to have a visual guide for this tutorial read on if you prefer textual content 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 create account folder on new account creation we will create a record triggered flow to automatically create account folder whenever a new account is created an opportunity sub folder will also be created within the account folder this is how the final flow looks like the details of the flow has been given below 1 create account folder using ‘create folder’ action create folder action can be used to create folders in any location on any cloud storage platform from salesforce flows we will use this action to first create the account’s parent folder note if you use a record triggered flow, make sure you run this action on an asynchronous path as shown below for detailed understanding, you can refer the gif below to use the “create folder” action, simply click on add element button and search for ‘create folder’ as shown below once you add this action, it will ask you to fill in certain parameters this action requires a few parameters here is a quick reference on what these are and how to get these for a detailed description, refer to the create folder https //help cloudfiles io/salesforce/create folder flow action detailed guide 1 library this is the desired cloud storage where you wish to create the folder possible values are sharepoint, google (for google drive), onedrive, dropbox, box, cloudfiles (aws s3) 2 folder name folder name is the name you wish to give your created folder we simply use the account’s name but you can also create a complex text formula variable as allowed by salesforce flows 3 destination parameters there are a few other parameters that help specify where the target folder should be created e g in sharepoint, which site, drive and parent folder should this folder get created in these parameters can be easily copied from within salesforce using the content library tab here is a quick reference of these parameters parent folder id this is the cloud drive generated id of the folder where you want to create this folder in drive id this is important for google drive & sharepoint users only these cloud storages offer multiple 'drives' where documents can be uploaded these parameters can be copied by accessing your cloud storage using cloudfiles from within salesforce follow these steps click on app launcher on top left search for the “cloudfiles” app in the cloudfiles app, select the content library tab go to your preferred cloud storage go to the target folder where you would like to place the created folders in click on ‘view metadata’ button as shown below a dialog box opens up which shows all the ids copy the id from here these steps have been shown in the gif below this flow action returns various values related to the newly created folder we will use the newly created folder’s id in the next step to create a sub folder for opportunity here’s what the final create folder action looks like 2 create opportunity sub folder using ‘create folder’ action to create opportunity sub folder, we can simply use the same ‘create folder’ action that we used above with a couple of simple tweaks change the ‘folder name’ to ‘opportunities’ or any desired name change the ‘parent folder id’ to the return value of the previous ‘create folder’ action this way, this new folder will get created inside the account’s folder we created previously here’s how your second create folder action should look like now that we have account and opportunities folder created, we want all of this to show up on the salesforce record we will use the ‘create attachment’ action to associate the account folder to the salesforce account record later we will use the cloudfiles widget to actually see and manage the folder from the record 3 show account folder on record using ‘create attachment’ action create attachment https //help cloudfiles io/salesforce/create attachment flow action action allows you to attach the created folders to salesforce record to use this action, simply click on add element button and search for ‘create attachment’ as shown below once you add this action, it will ask you to fill in certain parameters “drive id” and “library” parameters will be same as above add the remaining parameters as given below resource id id of your account folder you can get it from your earlier “create folder” action resource type folder salesforce record id id of the salesforce record → {!$record id} refer to the gif below to get a visual understanding of this step here’s how our final create attachment action looks like 4 save the opportunity sub folder id into custom property create a custom property to store the ‘opportunities’ sub folder’s id, which will facilitate the creation of nested new opportunity folders within the account’s folder in the next flow to do so, add ‘update triggering record’ action and store the output id from ‘create opportunity folder’ action into a custom field save and activate the flow refer to the gif below to get a visual understanding of this step once the account folder is created, we will create a flow to automatically create opportunity folders within the previously created opportunity sub folder once a new opportunity is created for the associated account record create nested opportunity folder within account folder we will create a record triggered flow to automatically create opportunities folder whenever a new opportunity is created this folder should be created within the opportunity sub folder of account folder this is how the final flow looks like the details of the flow has been given below 1 create opportunity folder using ‘create folder’ action to create opportunity folder, we can simply use the same ‘create folder’ action that we used above with a couple of simple tweaks change the ‘folder name’ to record name or any desired name for ‘parent folder id’, enter the custom property that we created in the previous step this will ensure the new opportunities folders are created within the opportunities sub folder of the account record here’s how your action should look like refer to the gif below to have a visual understanding of this step 2 show opportunity folder on record using ‘create attachment’ action to show opportunity folder on the record, we can simply use the same ‘create attachment’ action that we used above with a couple of simple tweaks once you add this action, it will ask you to fill in certain parameters “drive id”, “library”, “resource type” and salesforce record id” will be same as above for parent folder id, enter the id of your opportunity folder you can get it from your earlier “create folder” action save and activate the flow here’s how our final create attachment action looks like test the nested folders in action now that everything is setup, lets test our flow follow the steps below to see the nested folder in action simply create a new account record in salesforce and then go the ‘files’ tab that we added in the previous step the flow may take a few seconds to run so click on the refresh icon on top right of the widget once the folder is connected, the system might show you a “connect to sharepoint” button as shown below this is a one time login that your users will need to perform the first time they access cloudfiles using salesforce once you connect your sharepoint here, you should see the newly created account folder and opportunities sub folder now create a new opportunity and associate it to the account created earlier navigate to the ‘files’ tab you should be able to see newly created opportunity folder you can quickly navigate to sharepoint as shown below you will be able to cross check that the opportunity folder is created within the ‘opportunities’ sub folder of respective account folder these steps are illustrated in the gif below congratulations! you've successfully created nested folders based on object relationships using salesforce flows