Tutorials

Renaming a folder in Sharepoint when the Record is updated

In this guide, we'll show you how to rename an Account folder in Sharepoint linked to an Account record. We'll use CloudFiles flow actions to rename Sharepoint Account folders automatically when the Account name changes.

What to Expect

By the end of this tutorial, you can expect to -

  1. Have an Account folder created in Sharepoint for every new Account.
  2. Rename Sharepoint Account folders automatically when the Account name changes.

The GIF below shows the expected output.

Document image


Pre-requisites

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 page

Add the CloudFiles widget to Account page in order to view the files and folders within salesforce. Follow the steps below -

  1. Go to any Account record and click “Edit Page” Button.
  2. Lightning builder for this page will open. Insert a new tab and drag and drop the "CloudFiles" widget.
  3. Save and exit the builder. Refresh the Salesforce record page. The widget should now show up.
  4. Follow the above steps and add CloudFiles widget to the Lead record page as well.

Refer to the GIF below to get a visual understanding of this step. The inserted widget may show a blank screen but you don't need to worry about it. Move on to the next step.

Document image


Automatic folder creation for Accounts

For this tutorial, We require automated folders to be created upon the creation of new Account. To accomplish this, we will create a record-triggered flow using CloudFiles actions. For a comprehensive guide on the process of creating automated folders, please refer to our tutorial at Create Automated Folder Hierarchies for Managing External Files from Salesforce Objects.

This is how the flow would look like -

Document image


Flow - Account Folder Renaming on Account Name Change

In this section, we will create a flow to automatically rename the previously created and attached Account folder into the changed name. Firstly, we'll configure a Record Triggered Flow to initiate the automation process whenever an update is made to the Account name. Then, we'll retrieve the details of the Account folder. Finally, using CloudFiles action, we'll update the name of the folder into the new Account name.

This is how the final flow looks like -

Document image


The details of the flow has been given below -

1 - Configure a Record Triggered Flow

We will start by creating a record-triggered flow on the 'Account' Object. Follow the detailed instructions below for the input parameters -

  1. In the 'Configure Start' window, select Account as the object
  2. Configure trigger of the flow when a A record is updated
  3. For setting the Entry Conditions, follow the following steps
    1. Condition Requirements -> select All Conditions Are Met (AND)
    2. Define the condition as Field-> Name, Operator-> Is Changed, Value -> TRUE
  4. For When to Run the Flow for Updated Records, select Every time a record is updated and meets the condition requirements We have selected this option since we want the Flow to run everytime when the triggered record's name is changed.
  5. For Optimize the Flow For, select Actions and Related Records
  6. Check the Include a Run Asynchronously path checkbox.

The configuration looks like below -

Document image


The GIF below provides a visual understanding of this step -

Document image


2 - Get details of the Account folder

We will use Get Connected Folder Apex action to retrieve the details of triggering record's corresponding Account folder. Once you add the action, it will ask you to fill in a single parameter.

ParentId - Input the Salesforce Record Id whose connected folder is to be fetched. Here, input the flow triggering Account record Id as 'Record' > 'Account ID' i.e. {!$Record.Id}

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

Document image


In case the Salesforce Record, whose Id is input into the action has got a single folder attached to it, then Get Connected Folder will give the attached folder details as output. Here, by inputting the Record Id of the Lead that triggered the flow, the action yields the details of he folder attached to the Lead record. We will use this details in the next step to move the lead folder to account folder.

3 - Check Account folder connection

We will add a decision element to check whether there is any folder connected to the account record or not. This will be simple null check over the outputs the Get Connected Folder action used in previous step.

  1. Add a decision element with one configured oucome and a default outcome.
  2. Configure the first outcome i.e. in case of no folder connected to the account record.
    1. Enter a Label for the outcome.
    2. Condition Requirements to execute -> select All Conditions Are Met (AND)
    3. Define the condition as Resource-> Outputs from Get_Account_Folder > id, Operator-> Is Null, Value -> TRUE
    4. When to Execute Outcome, select If the condition requirements are met We have selected this option since we want the Flow to run everytime when the triggered record's name is changed.
  3. Enter a Label for the Default outcome. This path shall execute the upcoming actions.

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

Document image


4 - Create a CloudFiles Resource Variable

For execution of upcoming actions, we will have to create a CloudFiles Resource Variable.

  1. Create a new flow resource:
    1. Resource Type -> Variable
    2. Data Type -> Apex-Defined
    3. Apex Class -> cldfs__Resource
    4. Allow multiple values (collection)-> Unchecked

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

Document image


5 - Assign the Account Folder to CloudFiles Resource Variable

In the deafault outcome path, we will have to assign the Account Folder details output by action in step 2 to the created CloudFiles Resource Variable of step 4. For this:

  1. Add an Assignment element in the default outcome path.
  2. Map the Variable Values as:
    1. Cldfs_Resource > driveId -> Outputs from Get_Account_Folder > driveId
    2. Cldfs_Resource > id -> Outputs from Get_Account_Folder > id
    3. Cldfs_Resource > library -> Outputs from Get_Account_Folder > library
    4. Cldfs_Resource > path -> Outputs from Get_Account_Folder > path
    5. Cldfs_Resource > type -> Outputs from Get_Account_Folder > type

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

Document image


6 - Update Name of the Account Folder

We will use Set Resource Property Apex action to update the name property (Property API Name : name) of the Account folder. Once you add the action, it will ask you to fill in few parameters.

  1. Enter a Label for the Set Resource Property Action.
  2. Set Resource -> Cldfs_Resource (the variable used in the steps 4,5)
  3. Set only one property as: Name -> name== Value -> {!$Record.Name}

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



7 - Save and Activate the flow

Once the Flow is activated, whenever an Account's name is changed , this flow should automatically update the Account record connected Account folder name.

Document image


Test the Flows in action

Now that everything is setup, lets test our flows. Follow the steps below to see this automation in action.

  1. Create a new Account. This should create a Account folder (Folder name = Account Name) visible in the 'CloudFiles' widget on Account record page.
  2. Now change the Account name.
  3. Refresh the widget. You will find that the Sharepoint Account folder's name is automatically changed to the new Account name.

Flow execution and folder creation may take some time (a few seconds to a minute). If you don't see any changes, try refreshing the CloudFiles widget a couple of times.

Congratulations! You've successfully configured flows to Rename Sharepoint Account folders automatically when the Account name changes.