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.
By the end of this tutorial, you can expect to -
- Have an Account folder created in Sharepoint for every new Account.
- Rename Sharepoint Account folders automatically when the Account name changes.
The GIF below shows the expected output.
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.
Add the CloudFiles widget to Account page in order to view the files and folders within salesforce. Follow the steps below -
- Go to any Account record and click “Edit Page” Button.
- Lightning builder for this page will open. Insert a new tab and drag and drop the "CloudFiles" widget.
- Save and exit the builder. Refresh the Salesforce record page. The widget should now show up.
- 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.
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 -
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 -
The details of the flow has been given below -
We will start by creating a record-triggered flow on the 'Account' Object. Follow the detailed instructions below for the input parameters -
- In the 'Configure Start' window, select Account as the object
- Configure trigger of the flow when a A record is updated
- For setting the Entry Conditions, follow the following steps
- Condition Requirements -> select All Conditions Are Met (AND)
- Define the condition as Field-> Name, Operator-> Is Changed, Value -> TRUE
- 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.
- For Optimize the Flow For, select Actions and Related Records
- Check the Include a Run Asynchronously path checkbox.
The configuration looks like below -
The GIF below provides a visual understanding of this step -
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.
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.
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.
- Add a decision element with one configured oucome and a default outcome.
- Configure the first outcome i.e. in case of no folder connected to the account record.
- Enter a Label for the outcome.
- Condition Requirements to execute -> select All Conditions Are Met (AND)
- Define the condition as Resource-> Outputs from Get_Account_Folder > id, Operator-> Is Null, Value -> TRUE
- 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.
- 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.
For execution of upcoming actions, we will have to create a CloudFiles Resource Variable.
- Create a new flow resource:
- Resource Type -> Variable
- Data Type -> Apex-Defined
- Apex Class -> cldfs__Resource
- Allow multiple values (collection)-> Unchecked
Refer to the GIF below to get a visual understanding of this step.
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:
- Add an Assignment element in the default outcome path.
- Map the Variable Values as:
- Cldfs_Resource > driveId -> Outputs from Get_Account_Folder > driveId
- Cldfs_Resource > id -> Outputs from Get_Account_Folder > id
- Cldfs_Resource > library -> Outputs from Get_Account_Folder > library
- Cldfs_Resource > path -> Outputs from Get_Account_Folder > path
- Cldfs_Resource > type -> Outputs from Get_Account_Folder > type
Refer to the GIF below to get a visual understanding of this step.
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.
- Set Resource -> Cldfs_Resource (the variable used in the steps 4,5)
- Set only one property as: Name -> name== Value -> {!$Record.Name}
Refer to the GIF below to get a visual understanding of this step.
Once the Flow is activated, whenever an Account's name is changed , this flow should automatically update the Account record connected Account folder name.
Now that everything is setup, lets test our flows. Follow the steps below to see this automation in action.
- Create a new Account. This should create a Account folder (Folder name = Account Name) visible in the 'CloudFiles' widget on Account record page.
- Now change the Account name.
- 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.