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 -

  1. Have an Automated Account Folder and Opportunities sub-folder created when a new Account is created.
  2. Have nested folders for newly created opportunities within the associated account's Opportunities sub-folder.
  3. 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.

Document image


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 to know more.

Document image


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 or refer to the GIF below for a clearer understanding.

Document image


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.

Document image


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 -

Document image


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 -

Document image

Document image


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.

Document image


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 -

  1. Click on App Launcher on top left. Search for the “CloudFiles” App.
  2. In the CloudFiles App, select the Content Library Tab.
  3. Go to your preferred cloud storage. Go to the target folder where you would like to place the created folders in.
  4. 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 -

Document image


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 -

Document image


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.

  1. Change the ‘Folder Name’ to ‘Opportunities’ or any desired name.
  2. 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 -

Document image


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 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 -

  1. Resource Id: ID of your Account folder. You can get it from your earlier “Create Folder” action.
  2. Resource Type: folder
  3. Salesforce Record Id: ID of the Salesforce record → {!$Record.Id}

Refer to the GIF below to get a visual understanding of this step.

Document image


Here’s how our final Create Attachment action looks like -

Document image


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.

Document image


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 -

Document image


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.

  1. Change the ‘Folder Name’ to Record Name or any desired name.
  2. 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 -

Document image


Refer to the GIF below to have a visual understanding of this step

Document image


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 -

Document image


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.

  1. Simply create a new Account record in Salesforce and then go the ‘Files’ tab that we added in the previous step.
  2. The flow may take a few seconds to run so click on the refresh icon on top right of the widget.
  3. 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.
  4. Once you connect your SharePoint here, you should see the newly created Account Folder and Opportunities sub-folder.
  5. Now create a new opportunity and associate it to the account created earlier.
  6. Navigate to the ‘Files’ tab. You should be able to see newly created Opportunity Folder.
  7. You can quickly navigate to SharePoint as shown below.
  8. 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 -

Document image


Congratulations! You've successfully created Nested folders based on object relationships using Salesforce flows.