Getting Started with Salesforce Flow – Part 28 (Have a File Upload Component and Other Details on a Single Screen? Really? Wow!)

Getting Started with Salesforce Flow – Part 28 (Have a File Upload Component and Other Details on a Single Screen? Really? Wow!)

Last Updated on December 26, 2020 by Rakesh Gupta

Big Idea or Enduring Question:

If you do wonder then, know that you are not alone!

I often receive such requests either via email, as a comment on my website or, through Social Media. 

So, let us get started and tackle the challenge by creating a business use case. 

A few releases ago Salesforce introduced a new screen input component known as – File Upload. The component allows users to upload files – simple! 

For example, you can build a Flow that allows your sales rep to create an Opportunity and then attach a Pre-sales Evaluation file through the Flow. You can check my previous article Enhance Productivity by Uploading Files Directly from a Flow! to learn more about how to use the File Upload component. Mostly, we put the File Upload component on a separate screen as it requires a Related Record ID (The Id of the record to associate the files with. If no value is passed, the component is disabled). In this article, I will discuss some common challenges you might face regularly via the following use case.

Objectives:

After reading this blog, you’ll be able to: 

  • Create a screen with few screen components
  • Create a screen with a File component that allows users to upload multiple files 
  • Associate the files with the newly created record 

Business Use Case

Sergio Armendariz is an App Developer at GurukulOnCloud (GoC). He received a requirement to create a Flow that allows Business Development Reps to create a Lead and upload the Lead’s business card from a single screen.  
 
After reading this article this article Sergio learned how to handle the above use case using two screens. Sergio called his Solution Architect Rakesh Gupta to seek his advice to solve his use case without having to create a new screen.

Automation Champion Approach (I-do):

There are a few possible solutions for the above business scenario. However, our purpose, in this blog, is to learn Flow and its advanced/new features. Therefore, we will use Flow and the Upload File Component to solve the above business requirement 
 
Before diving further, 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. 

Maybe you too are wondering just like Sergio – Why does the above solution look so complex?! So, Sergio asked Rakesh – can’t we use something like this?: 

Unfortunately, the answer is NO. Sorry to disappoint you, Sergio, lamented Rakesh. 

Did I disappoint you too? Oh, sorry again. 

Are you still wondering why Sergio’s solution will not work? Well, let me cut the chase and explain to you why Sergio’s solution will not work. 

Sergio’s process flow works in the following order: 

  1. On the first step (screen element) users enter all the details and upload the files.
  2. Once users click on the Next button, the Flow will do two things:
    1. Insert Files into Content Document. This is so because the record Id (Lead Id) is not yet available. And therefore, the Flow will not be able to associate the files with the lead record. 
    2. As a result, the Flow will not be able to pass the data to Insert Lead (Create Record Component)
  3. In the next step, it will create a Lead.
  4. Stop

I hope by now you understand why Rakesh is taking a little longer route in his solution. Before proceeding ahead, understand the functionality of a ContentDocumentLink (It represents a link between a Salesforce CRM Content document or Salesforce file and where it’s shared) object in Salesforce.

Field Name Details
ContentDocumentId The ID of the document.
LinkedEntityId The ID of the linked object. Can include Chatter Users, Groups, records (any object that supports Chatter feed tracking including custom objects), and Salesforce CRM Content libraries. 
ShareType The permission granted to the user of the shared file in a library.

Let’s begin building this automation process.

Guided Practice (We-do):

There are 7 steps to solve Sergio’s business requirement using Salesforce Flow. First an overview:

  1. Create a variable to store content document IDs
  2. Create a screen that will allow users to enter Lead details and upload file(s)
  3. Add a create records element to insert Lead
  4. Add a loop element to extract records from collection variable (Content Document IDs) 
  5. Add an assignment element to assign the values into the Content Document Link record variable
  6. Add an assignment element to adding content Document Link record variable to a record collection variable (Content Document Link)
  7. Add a create records element to insert data from the record collection variable (Content Document Link)

Step 1: Create a Variable to Store Content Document IDs

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows then click on the New Flow.
  4. Select the Screen Flow option and click on Create.
  5. Clicks on the Manager tab then click on the New Resource
    1. Resource Type: Variable
    2. API Name: VarTContentDocumentIds
    3. Data type: Text
    1. Allow multiple values (collection): Yes
    2. Availability Outside the Flow
      1. Available for input
      2. Available for output
    3. Click Done.

Step 2: Adding Screen Component  

  1. Drag-and-drop Screen element onto the Flow designer. 
  2. Enter the Label (Lead Form) the API Name will auto-populate.
  3. On the Screen element, navigate to the Input section and double-click on the Name field to add it to the Screen element
    1. Enter the Label (Name) the API Name will auto-populate.
  4. On the Screen element, navigate to the Input section and double-click on the Text field to add it to the Screen element
    1. Enter the Label (Company) the API Name will auto-populate.
  5. On the Screen element, navigate to the Input section and double-click on the File Upload component to add it to the Screen element
    1. Enter the Label (Visiting Card) the API Name will auto-populate.
    2. Select Manually assign variables (advanced)Store Output Values to Select Variables
      1. Content Document IDs: {!VarTContentDocumentIds}
  6. Click Done.

Step 3: Salesforce Flow – Adding a Create Records Element to Create a Lead

  1. Drag-and-drop the Create Records element onto the Flow designer. 
  2. Enter a name in the Label (Create a Lead) field; the API Name will auto-populate.
  3. For How Many Records to Create – select One.
  4. For How to Set the Record Fields – select Use separate resources, and literal values.
  5. Select the Lead object from the dropdown list.
  6. Set Field Values for the Lead
    1. Row 1:
      1. Field: Company
      2. Value: {!Company}
    2. Click Add Row
    3. Row 2:
      1. Field: LastName
      2. Value: {!Name.lastName}
    4. Click Add Row
    5. Row 3:
      1. Field: FirstName
      2. Value: {!Name.firstName}
  7. Click Done.

Step 4: Salesforce Flow –  Add a Loop Element to Retrieve Records from Collection Variable 

  1. Drag-and-drop the Loop element onto the Flow designer. 
  2. Enter a name in the Label (Extract Record) field – the API Name will auto-populate.
  3. For Collection Variable select {!VarTContentDocumentIds}.
  4. For Specify Direction for Iterating Over Collection select the option First item to last item.
  5. Click Done.

Step 5: Salesforce Flow – Adding an Assignment Element to Assign the Values into a Record Variable

  1. Create a Record Variable varRContentDocumentLink type Content Document Link to link the File with the lead record.
  2. Drag-and-drop the Assignment element onto the Flow designer. 
  3. Enter a name in the Label (Link File and Lead Record) field – the API Name will auto-populate.
  4. Set Variable Values
    1. Row 1:
      1. Field: {!varRContentDocumentLink.ContentDocumentId}
      2. Operator: Equals
      3. Value: {!Extract_Record}
    2. Add Assignment 
    3. Row 2:
      1. Field: {!varRContentDocumentLink.LinkedEntityId}
      2. Operator: Equals
      3. Value: {!Create_a_Lead}
  5. Click Done.

Step 6: Salesforce Flow –  Adding an Assignment Element to Add the Record Variable to Record Collection Variable

  1. Create a Record Collection Variable varRContentDocumentLinks type Content Document Link to store record variable (created in step 5.1) for the bulk process.
  2. Drag-and-drop the Assignment element onto the Flow designer. 
  3. Enter a name in the Label (Add Records into a Collection) field – the API Name will auto-populate.
  4. Set Variable Values
    1. Row 1:
      1. Field: {!varRContentDocumentLinks}
      2. Operator: Add
      3. Value: {!varRContentDocumentLink}
  5. Click Done.

Step 7: Salesforce Flow – Adding a Create Records Element to Associate Files and Lead Record 

  1. Drag-and-drop the Create Records element onto the Flow designer. 
  2. Enter a name in the Label (Create Records from Collection) field- the API Name will auto-populate.
  3. For How Many Records to Create select Multiple.
  4. Map Record Collection: {!varRContentDocumentLinks}
  5. Click Done.

In the end, Sergio’s Flow will look like the following screenshot:

 Whew! I know, the journey was a bit long! But, despair not, we are almost there!

Almost there! Once you’re done, Save the flow. 

Do not forget to activate the Flow by clicking on the Activate button.

Note:- Before you activate your process, you will want to make sure that you have assigned data in the correct format. This is because Salesforce Flow obeys validation rules. If some fields are required by validation rules then, make sure you add those fields. Conversely, if some fields are required on the page layout, you can ignore those fields.

It’s time to test this feature

Next time, when a Sales rep creates leads using the above flow – they will not have to move screen by screen. Instead, the sales rep can enter all the details – including files – into a single screen. what a great way to boost users’ productivity.  

If you have any problem with watching the video then, please click on it and open it in another tab.

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.

Proofreader: - Munira Majmundar
Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.