Set a Default Value for Record Choice Set for Screen Flow? Sure,Why Not?!

Set a Default Value for Record Choice Set for Screen Flow? Sure,Why Not?!

Last Updated on February 10, 2022 by Rakesh Gupta

Big Idea or Enduring Question:

Surprised, that setting a pre-selected default value for a Record Choice component is not easy? If so then, one thing to remember is that with enough creativity and persistence, Salesforce Flows’ versatility is such that you can design a solution for almost any business requirement. 

So, the moral of the story is – think out-of-the-box. Just because something has not been done before does not mean it cannot be tried and done 😇  With this enthusiastic note, let us get started!

As we all know, setting a default value for Choice or Picklist Choice Set is straightforward. However, as we all also know, setting a pre-select (default) value for a Record Choice Set is a different ball game altogether – It requires us to think how we can use the malleable functionalities of Salesforce Flow to design a solution. In this case, we will be achieving our objective by leveraging a Get Record Element. 

In this article we will go through a real life scenario to understand how we can pre-select a choice for a Record Choice set.

Objectives:

This blog post will help us to understand the following:

  • How to work with the Radio Button component – Screen Flow.
  • How to Create a Record Choice Set.
  • How to set up a default value for Radio Button.
  • How to Create a Quick Action to launch a Flow.

Business Use Case

Brenda David is working as a System Administrator at Universal Containers (UC). As part of her objective to streamline Sales processes, Brenda received following requirements:

  • On click of a button on the Opportunity, pop-up a screen.
  • Display all Contacts from the Opportunity Contact Role of the current Opportunity.
  • Set Primary Contact of the Opportunity as a default pre-selected value.

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 requirement. The main reason for selecting a Screen Flow is that we want to allow users to provide an input. 


Before discussing the solution, let me show you a diagram of a Process Flow at a high level. Please spend a few minutes going 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 the Screen Flow. We must:

  1. Creating a Custom Formula Field on the Opportunity Contact Role Object to Display Contact Name.
  2. Next, take the following Salesforce Flow Steps – Define flow properties:
    1. Create a Text Variable to Store Current Opportunity’s Id.
    2. Add a Get Record Element to Find the Primary Contact on an Opportunity.
    3. Add a screen element to capture the user’s input:
      1. Add a Radio Button Component to Display Contact Role from the Current Opportunity.
      2. Add Default Value to the Radio Button.
  3. Create a Quick Action to Launch the Flow.

Step 1: Creating a Custom Formula Field on the Opportunity Contact Role Object to Display Contact Name 

On the Opportunity Contact Role object, create a formula field called Contact Name as mentioned in the steps below. 

  1. Click Setup.
  2. In the Object Manager, type Opportunity Contact Role.
  3. Select Fields & Relationships, then click New.
  4. Select Formula as Data Type, then click Next.
  5. Enter Field Label and click the Next button. The API Name will populate. 
  6. Select Text as Formula Return Type, then click Next.
  7. Now enter Contact.FirstName’& ‘&Contact.LastName in the Value.
  8. Set the Field-level Security for the profiles, make sure to grant field access to profiles. 
  9. Add this field to Page Layout.
  10. Click Save.

Step 2: Salesforce Flow – Define Flow Properties   

  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 Next and configure the flow as follows: 
    1. How do you want to start building: Freeform
  5. It will open the flow designer for you.

Step 2.1: Salesforce Flow – Create a Text Variable to Store Current Opportunity’s Id

  1. Under Toolbox, select Manager, then click New Resource to store the current opportunity Id. 
  2. Input the following information: 
    1. Resource Type: Variable
    2. API Name: recordId
    3. Data Type: Text
    4. Default Value: {!$GlobalConstant.EmptyString}
    5. Check Available for Input
    6. Check Available for Output
  3. Click Done.

Step 2.2: Salesforce Flow – Adding a Get Record Element to Find the Primary Contact on An Opportunity 

The next step is to find the primary contact on the current Opportunity. We will use the Get Records element. To do this, drag-and-drop Get Records element onto the canvas and map the fields according to the details below:

  1. Under Toolbox, select Element
  2. Drag-and-drop Get Records element onto the Flow designer. 
  3. Enter a name in the Label field; the API Name will auto-populate.
  4. Select the Opportunity Contact Role object from the drop-down list.
  5. Select All Conditions Are Met (AND)
  6. Set Filter Conditions
    1. Row 1:
      1. Field: IsPrimary
      2. Operator: Equals
      3. Value: {!$GlobalConstant.True}
    2. Row 2:
      1. Field: OpportunityId
      2. Operator: Equals
      3. Value: {!recordId}
  7. How Many Records to Store:
    1. select Only the first record
  8. How to Store Record Data:
    1. Choose the option to Automatically store all fields
  9. Click Done.

Step 2.3: Salesforce Flow – Add a Screen Element to Capture the User’s Input  

  1. Under Toolbox, select Elements. Drag and drop Screen onto the canvas. 
  2. Input the following information:
    1. Enter Label the API Name will auto-populate.
  3. Click Done

Step 2.3.1: Salesforce Flow – Add a Radio Button Component to Display Contact Role from the Current Opportunity 

  1. Under Input section on Screen Element. Drag and drop the Radio Buttons component onto the screen. 
  2. Input the following information:
    1. Enter a name in the Label field; the API Name will auto-populate.
    2. Under Select Choices 
      1. Click + New Resource, it will open a pop-up for you
      2. Resource Type: Record Choice Set
      3. API Name: recChoiceContact
      4. Object: Opportunity Contact Role
      5. Filter Opportunity Contact Role Records
        1. Row 1:
          1. Field: OpportunityId
          2. Operator: Equals 
          3. Value: {!recordId}
      6. Configure Each Choice
        1. Choice Label (Select a field that generate label for each choices): Contact_Name__c
        2. Data Type (Data type of the choice’s value): Text
        3. Choice Value (Select a field whose value you want to store when the user selects this choice at run time): ContactId
      7. Click Done
  3. Click Done.

Step 2.3.2: Salesforce Flow – Add Default Value to the Radio Button 

Now, we will pre-selected choice for the Radio Button – select a contact. 

  1. Under the Radio Button Component navigate to the Default Value section. 
  2. Now we will define the default value for Radio Button using get element from Step #2.2.
    1. Default value: {!getPrimaryContact.ContactId}
  3. Click Done.

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

Once everything looks good, perform the steps below: 

  1. Click Save.
  2. Enter Flow Label the API Name will auto-populate.
  3. Click Show Advanced.
  4. How to Run the Flow: API Version for Running the Flow: 52
  5. API Version for Running the Flow: 52
  6. Interview Label: Set a Default Value for Dynamic Record Choice {!$Flow.CurrentDateTime}
  7. Click Save

Almost there! Once everything looks good, click the Activate button.

Step 3: Create a Quick Action to Launch the Flow

The next step is to create a Quick Action (Key Contact) on the Opportunity object to launch the Flow. Salesforce will automatically pass the Contact Id to the recordId variable.

  1. Click Setup.
  2. In the Object Manager, type Opportunity.
  3. Select Buttons, Links, and Action, then click New Action.
  4. Input the following information:
    1. Select Flow as Action Type.
    2. Select Default value for Dynamic Record Choice as Flow.
    3. Enter Label (Key Contact) the Name will auto-populate.
  5. Click Save.

Make sure to add the Quick action to the Opportunity Lightning Record Pages. 

Proof of Concept

From now onwards, whenever a user clicks on the Key Contact button, Flow will populate a screen with Primary contact selected as a default value! Voila!

Formative Assessment:

I want to hear from you!  

What did you learn from this post, is it relevant to you, and how will you modify the concepts taught in the post for your own business processes?  

Make a post and tag me on Twitter @automationchamp using #AutomationChampionFlow.

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.