Last Updated on February 10, 2022 by Rakesh Gupta
Big Idea or Enduring Question:
How do you allow Sales reps an easy to transfer their files to another user?
The file allows you to Upload, Share, Follow files in Salesforce. The file helps the organization to discuss changes to the file in real-time, from whatever device they are using. It also cuts down on email traffic and keeps all comments with the related documents for easy reference.
If a file is private, then the file owner and users with Modify All Data permission can find and view this file. However, if the file is in a private library, only the file owner has access to it. This is one pain point for System administrators how to migrate files from a user to another user because the business doesn’t want to lose all files owned by a user whom they are planning to deactivate.
Objectives:
This blog post will help us to understand the following
- Use a Screen a flow to take the user input
- Create automation to mass transfer files
- Learn more about the ContentDocument object.
Business Use Case
Brenda David is working as a System administrator at Universal Containers (UC). As a part of the employee offboarding process, management wants to provide a tool to their employees so that they can easily transfer their files to another user.
Automation Champion Approach (I-do):
There are a few possible solutions for the above business scenario, but I’ll use Screen Flow to solve the business requirement.
Field Name | Details |
OwnerId | The Id of this document. |
FileType | Type of document, determined by the file extension. |
Before discussing the solution, let me show you a diagram of a Process Flow at a high level. Please spend a few minutes to go through the following Flow diagram and understand it.
Let’s begin building this automation process.
Guided Practice (We-do):
There are 3 steps to solve Brenda’s business requirement using Screen Flow. We must:
- Create a custom field to store the user’s offboarding date
- Salesforce Flow Steps: (Screen Flow)
- Add a screen to capture the user data
- Add a lookup component
- Add update records element to transfer file ownership
- Add a screen to capture the user data
- Add flow to the lightning home page
Step 1: Creating a Few Custom Fields on the User object to Store the Offboarding Date and Offboarding Started (Formula)
First of all, we will create the following fields on the user object to store the offboarding date and other information. We will also create a formula field to calculate when to show or hide components on the lightning home page.
Field Name | Data Type | Formula |
Date To Offboard | Date | |
Offboarding Started? | Formula (Checkbox) | IF(Date_To_Offboard__c >= TODAY() && NOT(ISNULL(Date_To_Offboard__c)), True, false) |
- Click Setup.
- In the Object Manager, type User.
- Select Fields & Relationships, then click New.
- Select Date as Data Type, then click Next.
- Enter Field Label and click the tab key, the API Name will populate.
- As a best practice, always input a description.
- Set the Field-level Security for the profiles, make sure to set this field as read-write for the right people, mainly system administrators.
- Add this field to Page Layout.
- Click Save.
Step 2.1: Salesforce Flow – Add a Screen Element
- Click Setup.
- In the Quick Find box, type Flows.
- Select Flows then click on the New Flow.
- Select the Screen Flow option and click on Next and configure the flow as follows:
- How do you want to start building: Freeform
- Under Toolbox, select Elements. Drag and drop Screen onto the canvas.
- Input the following information:
- Enter Label the API Name will auto-populate.
- Click Done.
Step 2.1.1: Add a Lookup Component to Capture the User Name To Whom They Want to Transfer Files
- Under Input section on Screen Element. Drag and drop the Lookup component onto the screen.
- Input the following information:
- Enter API Name.
- Field API Name: CreatedById (Enter the field API Name that will show up in the list box to represent a record.)
- Label: Transfer To (Enter a label that appears next to the lookup control)
- Object API Name: Account ( Enter the object API name)
- Required: {!$GlobalConstant.True}
- Click Done.
Step 2.2: Lightning Flow – Update Records – Transfer File Ownership
The next step is to transfer the file ownership. or this, we will use an Update Record element.
- Under Toolbox, select Element.
- Drag-and-drop Update Records element onto the Flow designer.
- Enter a name in the Label field; the API Name will auto-populate.
- Click Specify conditions to identify records, and set fields individually
- Object: Content Dcoument
- Select All Conditions Are Met (AND).
- Set Filter Conditions
- Row 1:
- Field: OwnerId
- Operator: Equals
- Value: {!$User.Id}
- Row 1:
- Set Field Values for the Case Records
- Row 1:
- Field: OwnerId
- Value: {!TransferTo.recordId}
- Row 1:
- Click Done.
In the end, Brenda’s Flow will look like the following screenshot:
Once everything looks good, perform the steps below:
- Click Save.
- Enter Flow Label the API Name will auto-populate.
- Click Show Advanced.
- Type: Screen Flow
- API Version for Running the Flow: 51
- Interview Label: Mass Transfer File {!$Flow.CurrentDateTime}
- Click Save.
Almost there! Once everything looks good, click the Activate button.
Step 3: Add a Flow to Lightning Home Page and Add Filter Criteria
The next step is to distribute a flow to Lightning Experience or Salesforce app users, by embedding it in a Lightning home page.
- Click Setup.
- In the Quick Find box, type Lightning App Builder.
- Select Lightning App Builder then click on the Edit next to the Home page.
- From the Lightning Components pane on the left, drag the Flow component onto the Lightning page canvas.
- Input the following information:
- Click Done.
Once everything looks good, click the Save button.
Proof of Concept
Now onwards, Sales users can this tool and transfer their files to another rep.
- Now, I am going to update the Date To offboard field on Nathan Gilmore’s user record.
- Now user Nathan Gilmore’s logged-In to his account, currently he owns three files.
- The next step is for Nathan to use the tool and transfers his files to Hasim Saikh.
- In the end, Nathan navigates backs to the File tab to verify that all his files transferred to Hasim.
Formative Assessment:
I want to hear from you!
What is one thing you learned from this post? How do you envision applying this new knowledge in the real world?
Let me know by Tweeting me at @automationchamp, or find me on LinkedIn.
Hi Rakesh,
In the above problem in step 2.1.1 you have specified Object Api Name as Account ..Why did u select Account over there?
To create a user lookup. Now we have different ways to create a lookup component, check them out:
Create Filtered Lookup with Choice Lookup
Create Lookup with Dynamic Forms for Flow
Select Multiple Records in the Lookup Component
Hi Rakesh,
In the above problem in step 2.1.1 you have specified Object Api Name as Account ..Why did u select Account over there?
Hi Rakesh,
First of all thanks for this post , this is very much useful.
I have a scenario wherein i want a File owner to be able to change the ownership of only one File is this doable through flow.
Thanks,
Harry
Only for one file? Why not doing it manually?
I would like to see if this is still validate and that there is no NEW COOL enhancements.
I have a use case where I need to have a workflow set up to have all chatter files associated with a public chatter groups assigned to the group owners to delete where they see fit.
As far as I know, there are no other way to achieve it.
Awesome! I don’t suppose you’ve found a way to duplicate files instead of just moving them? I’m stumped on that one so far.
Thanks Mark!. Yes you are right I never tried to find duplicate files but it’s a good idea. I will try it tomorrow, how you are trying to find duplicated files based on title or version ?
Ooh now that I think about it, I was trying to duplicate Attachments, not Files. But if that didn’t work and I could duplicate Files, that would be a viable alternative.
I’d be looking to duplicate all Attachments or Files associated with the source Opportunity. The Business Use Case is for opps where the salesman has procured a graphic during the sale that needs to go to the implementation team in another custom object once the opp is Closed Won.
Let me try this.