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.
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.
Refer to the quick video if you would like to have a visual guide for this tutorial. Read on if you prefer textual content.
Before you start with the set-up, please ensure these steps are completed.
CloudFiles is available on the Salesforce AppExchange and can be installed using the standard app installation process. Check out Installation Guide to know more.
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 or refer to the GIF below for a clearer understanding.
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.
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 -
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 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 -
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.
Create Attachment 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 -
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.
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 -
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
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 -
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.