Have a File Upload Component and Other Details on a Single Screen? Really? Wow!

Have a File Upload Component and Other Details on a Single Screen? Really? Wow!

Last Updated on February 10, 2022 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!

Preferred Timing(required)

 

26 thoughts on “Have a File Upload Component and Other Details on a Single Screen? Really? Wow!

  1. Hello can ypu help me with this issue:

    Componente Lightning: FacturaArchivo
    Componente de pantalla: forceContent:fileUpload
    Entradas:
    label = (Archivo)
    Salidas:
    contentDocIds = VarTContentDocumentIds ([null])

    Botón de navegación seleccionado: SIGUIENTE
    CREAR REGISTROS: Crear Factura
    Crear un registro Factura__c donde:
    Email__c = {!emailalmacenado} ()
    Emitido_a__c = {!ListaEmitidoa} (GENETHIC SERVICES 🧬)
    FOLIO_FISCAL__c = {!Folio_fiscal} (0AB000CF-0000-000A-00CF-0000FD0000A3)
    Factura_Estatus__c = Nuevo
    RecordTypeId = {!Iddetipoderegistro} (012Rd000000XuEj)
    Resultado
    Un registro está listo para crearse cuando se ejecute la siguiente pantalla, pausa o acción local o cuando finalice la entrevista.
    a4zRd0000004UtxIAE
    BUCLE: Extraer registro
    Bucle de paso: []
    Iteración: 0
    Elemento de iteración actual: null
    ASIGNACIÓN: rchivo de enlace y registro de cliente potencial
    {!varRContentDocumentLink.ContentDocumentId} Es igual a {!Extraer_registro}
    {!varRContentDocumentLink.LinkedEntityId} Es igual a {!Crear_Factura}
    Resultado
    {!varRContentDocumentLink.LinkedEntityId} = “a4zRd0000004UtxIAE”
    {!varRContentDocumentLink.ContentDocumentId} = “null”
    ASIGNACIÓN: Agregar registros a una colección
    {!varRContentDocumentLinks} Agregar {!varRContentDocumentLink}
    Resultado
    {!varRContentDocumentLinks} = “[ContentDocumentLink (Sin Id.)]”
    BUCLE: Extraer registro
    Finalizar bucle.
    CREAR REGISTROS: Crear registros de la colección
    Crear registros ContentDocumentLink empleando los valores que están almacenados en {!varRContentDocumentLinks}.
    Valores de variable
    [ContentDocumentId=null,LinkedEntityId=a4zRd0000004UtxIAE]
    Resultado
    Fallo al crear los registros.
    Se produjo un error: Este error se produjo cuando el flujo intentó crear registros: INVALID_CROSS_REFERENCE_KEY: invalid cross reference id. Puede buscar los valores de ExceptionCode en la Guía del desarrollador de la API de SOAP.

  2. Hi!
    Did you know a way to show the files uploaded in the same screen? This component is fault because didn’t show the files and pass a feeling of something wrong.
    If you know a way, please tell me

  3. Hi Rakesh, It’s Nice Explanation and good solution.

    In this solution you created on lead record with attachment, But i want to create Multiple leads in one click, May be in that screen i need ADD button and another lead with attachment

    Is that possible ? .

    If Possible , please give me basic idea

  4. Hi Rakesh, It’s Nice Explanation and good solution.

    In this solution you created on lead record with attachment, But i want to create Multiple leads in one click, May be in that screen i need ADD button and another lead with attachment

    Is that possible ? .

  5. Is it allowed if we upload files one after another, without attaching multiple documents at a time in File upload standard component.
    if we can upload files one after another, can u tell me the way how it’ll work

  6. Similar to the above issue with SF Admin, using customer community plus license type get an INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY: insufficient access rights on cross-reference id: xxxxx. Works fine as admin etc, but not sure what access the community plus user needs in addition as they have read,create,edit access on the linked record?

    1. After uploading the file through ‘Custom Community User,’ it seems the like user lost access to it. There are a few ways to solve it:

      1. Run your Flow in System mode, if it is not possible
      2. Then store the contentDocumentIds into a field on Lead then use record-triggered flow
      3. Split the screen flow into two screens, one to create a record, the second for uploading the file (and use related record Id, in the file component)

  7. Thanks Rakesh, this is awesome, very clear instruction. I followed the step by step and got it working for an authenticated site. However it doesn’t work for a public site.

    After the case was created. Below was what I have. Any idea why ?

    ***********************************************************************************************************************

    LOOP: Extract File Records
    Loop Through: []
    Iteration: 0
    Current iteration item: null

    ASSIGNMENT: Link File and Case Record
    {!vaRContentDocumentLink.ContentDocumentId} Equals {!Extract_File_Records}
    {!vaRContentDocumentLink.LinkedEntityId} Equals {!Create_Case_Record}
    Result
    {!vaRContentDocumentLink.ContentDocumentId} = “null”
    {!vaRContentDocumentLink.LinkedEntityId} = “XXXXXXXXx”

    ASSIGNMENT: Add Records into a Collection
    {!vaRContentDocumentLinks} Add {!vaRContentDocumentLink}
    Result
    {!vaRContentDocumentLinks} = “[ContentDocumentLink (No ID)]”

    LOOP: Extract File Records
    End Loop.

    CREATE RECORDS: Create Records from Collection
    Create ContentDocumentLink records using the values that are stored in {!vaRContentDocumentLinks}.
    Variable Values
    [ContentDocumentId=null,LinkedEntityId=XXXXXXXXx]
    Result
    Failed to create records.

  8. I got this issue when try to insert a record with Attachment files.
    An error has occurred: This error occurred when the flow tried to create records: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY: You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary.. You can look up ExceptionCode values in the

  9. Hi

    Thank you putting it together.

    I’m also i am getting this issue:

    ASSIGNMENT: Add record to Collection
    {!varContentDocumentLinks} Add {!varContentDocumentLink}
    Error
    The data type of the resource you entered isn’t compatible.

    Note : vaRContentDocumentLink is a Record(Single) Variable and !varContentDocumentLinks is a Record Collection Varaiable

    the second assignment isn’t working, how to resolve this ?

    Ta!

  10. Hi

    Thanks for this it has assisted me in getting the process to function.

    However, it does work when I attempt to debug in flow builder but once embedded in a site VF page, the file upload process fails to complete work. It does allow for the file to be selected, but the modal page doesn’t come up showing the progress of the load. All the other parts of the process (a custom create case process) does work.

    I suspect it is a Guest Permission issue but as the selection of the file to upload does function, I am not entirely sure.

    Your thoughts?

      1. Hi. you are referring to the Debug logs?

        The issue I have is that I can’t access this site on work computer and I am not able to send files outside of network.

        It does create the case, but the file isn’t loaded. This is when the flow is initiated via a VF page as a GUEST. My understanding is that there is an issue with GUESTS not being able to upload files due to permission changes by Salesforce and limited or no access to Document object.

        While the option to upload does appear and I can select the file to upload, it doesn’t give the progress box showing the file is being uploaded.

        Is there something I should look for in the logs to indicate issue with file upload?

  11. Hey
    how are you
    thanks for collaborate this information. it is really helps

    i have an issue with public site to do with process. it should work also internally ?

    also i am getting that issue:

    ASSIGNMENT: Add record to Collection
    {!varContentDocumentLinks} Add {!varContentDocumentLink}
    Result
    {!varContentDocumentLinks} = “[ContentDocumentLink (No ID)]”

    the second assignment isn’t working
    any reason why ?

    thanks

  12. It worked. The sharing was with all users. The issue was I was using “debug” feature, wherein the file was getting uploaded under “Admin” user (even though I selected “Log in as another user”).
    Once I deployed to the portal it worked as you have done above.
    Thanks for the elaborate explanation.

  13. I am facing issues while doing the above with community users.

    Error: Create Records from Collection “INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY: insufficient access rights on cross-reference id. You can look up ExceptionCode values in the”

    Reason: After we upload the document it gets auto created under “Content Document”.
    When we try to add the linkedEntityId in “Create Records from Collection” , SF does not allow us update.

    Note: The object sharing settings is public read write.

Leave a Reply

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

Discover more from Automation Champion

Subscribe now to keep reading and get access to the full archive.

Continue reading