How To

Create a Record Link Dynamically in Flow

ClickHere

There are times in which you want to provide a link to a record in flow, but this link needs to be created dynamically. It cannot be static, hardcoded. Now, you know what I think about hardcoding things, especially in flow.

Here are a few lessons learned from implementing this use case:

  • Reference “{!<formula resource>}” in the link to provide a hyperlink to the record detail page.
  • Create a variable to hold the newly created record.

Business Use Case:  Addison Dogster is the system administrator at Universal Containers. Mary Markle is the Operations manager. When a new contact record is created, she would like a confirmation screen that has a link to the newly created record. Is that possible, Addison? 

Solution: Why yes, it is indeed possible and can be generated dynamically. Addison Dogster solved this problem using a formula that dynamically generates the Salesforce URL to the newly created record.

Here is a demo of the solution:

RecordDetailLinkDemo

View image full screen

The automation solution (screen flow) looks like this:

CreateaNewContact-Flow

(1) We ask for the contact’s first and last name. (2) Then, we create the new contact record using the input from the screen flow and store the newly created contact record in a variable. (3) Lastly, we create the confirmation screen, letting the user know that we created the contact with a link to the newly created record.

Highlighted Steps: 

1. Create the screen flow shown above. In Lightning Experience, it is found under Process Automation | Flows. Click on “New Flow.” Select Screen Flow. For those using Salesforce Classic, flow can be found in Create | Workflows & Approvals | Flows. Select the Screen Flow and click the Create button.

In the flow, we would configure the following flow resources.

A. We need to create a variable resource to store the newly created Contact record Id.

Best practice tip: Provide a description so you and other/future admins know what this flow resource is used for.

This is how that flow resource would be configured.

  • Resource Type: Variable
  • API Name: varNewContact
  • Data Type: Text
  • Availability Outside the Flow:
    • Available for input: Unchecked
    • Available for output: Unchecked

varNewContact

B. We need to create a formula to store dynamically generated URL to the contact record. Because the contact record Id does not exist until it is created, we need to create the link dynamically. While we could have hardcoded the beginning URL, we want the link to work in every environment this is tested in and not just production.

Best practice tip: Provide a description so you and other/future admins know what this flow resource is used for.

This is how that flow resource would be configured.

  • Resource Type: Formula
  • API Name: NewContactLinkFormula
  • Data Type: Text
  • Formula: LEFT($Api.Partner_Server_URL_260, FIND( ‘/services’, $Api.Partner_Server_URL_260)) & {!varNewContact}

This part of the formula “LEFT($Api.Partner_Server_URL_260, FIND( ‘/services’, $Api.Partner_Server_URL_260))” will create the part of the URL before the record Id, such as “https://jenwlee-preview-dev-ed.my.salesforce.com.&#8221;

This part of the formula ” & {!varNewContact}” takes the user to the newly created contact recordId.

NewContactLink

C. First, we configure a Screen flow element called Create a Contact to collect the contact’s first and last name. (Note: For simplicity of this blog post, we are only collecting two pieces of information. In the real world, you would collect much more. Ensure that you are including fields that are required when creating a new contact in your org.)

Best practice tip: Provide a description so you and other/future admins know what this flow element is used for.

Configure as follows:

  • Screen Properties:
    • Control Navigation: deselect Pause and Previous
  • Add a Name Component Text:
    • API Name: ContactName
    • Fields to Display: firstName,lastName
    • Label: Contact Name

CreateaNewContact-Screen

View image full screen

CreateaNewContact-Screen1View image full screen

D. Next, we will add a Create Records flow element called Create a Contact where we will create a new contact based on the first and last name provided in the screen flow and then we will store the newly created Id in the variable varNewContact.

Best practice tip: Provide a description so you and other/future admins know what this flow element is used for.

Configure as follows:

  • How Many Records to Create: One
  • How to Set the Record Fields: Use separate resources, and literal values
  • Object: Contact
  • Set Field Values for the Contact:
    • First Name: {!ContactName.firstName}
    • Last Name: {!ContactName.lastName}
  • Manually assign variables: checked
    • variable: varNewContact

CreateaNewContact-CreateRecordView image full screen

E. Lastly, we have a final screen flow element called Confirmation to show a confirmation message with a link back to the newly created contact record page. To create a link to the record page, you click on the hyperlink icon Link and enter “/{!NewContactLinkFormula}.

Best practice tip: Provide a description so you and other/future admins know what this flow element is used for.

Configure as follows:

  • Screen Properties:
    • Control Navigation: Deselect Previous and Pause
  • Add a Display Text Component
    • API Name: ConfirmText
    • Text

You successfully created a contact: {!ContactName.firstName} {!ContactName.lastName} [Link: {!NewContactLinkFormula}]

CreateaNewContact-Screen2View image full screen

CreateaNewContact-Screen2aView image full screen

F. Toggle on Auto-Layout.

CreateaNewContact-Flow

G. Debug the flow to ensure it is working as expected.

H. Save your flow. Let’s call it Create a New Contact.

Best practice tip: Provide a description so you and other/future admins know what this flow is for.

CreateaNewContact-FlowProperties

I. Activate the flow.

J. You need to determine how your user will access the flow screen and configure the component accordingly.

Deployment Notes/Tips:

  • Flow, and related components can be deployed to Production in a change set (or can be deployed using a tool such as Metazoa’s Snapshot).
  • You will find the flow in a change set under the Flow Definition component type.
  • Activate the flow post deployment as flows deploy inactive in Production, unless you have opted in on the Process Automation Settings screen, to “Deploy processes and flows as active.” NOTE: With this change, in order to successfully deploy a process or flow, your org’s Apex tests must cover at least 75% of the total number of active processes and active autolaunched flows in your org or you can select 0%, which will run the apex classes not related to your flow.