TIPS & TRICKS #FLOW

Use Case

  • A company has created a custom object linked to the Lead & needs those records to be parented to the Opportunity upon conversion
  • The Opportunity relationship field should not be visible on the child records when still on the Lead phase, and the Lead relationship field should not be visible on the child records once linked to the Opportunity, neither when child records were created before Lead Conversion or after.

The Trick!

  1. Create the custom child Object linked to Lead & to Opportunity

For this example, let’s take the case of a Company storing Travel (custom Object) records under the Lead Object & needs these records to be brought across to the Opportunity upon Lead conversion.

The Custom Object needs to be created with its fields & page layout. 

  • Add a lookup field to Lead and one to Opportunity. These cannot be master-detail relationships because a Travel record can be created during the Lead phase when the Opportunity doesn’t exist yet, or during the Opportunity phase independently from any Lead. 
  • Add a checkbox field called “No UI Converted from Lead”. Have its security settings as read only for all Profiles & state in its description that this field is populated via the Flow and will be used to filter component visibility on the Dynamic Lightning Pages (later on). 
  1. Create the Flow

The Flow is going to Loop through each Items (Travel records) that are linked to the Lead, assign new values to the Opportunity & “No UI Converted from Lead” fields, and add these records with their new values to a List of Record. Once all Items have been looped through, the Flow is going to run the Update on the records in this latter list.

Flow Type: Record Triggered

Configure Start: 

  • Object: Lead
  • Trigger the Flow When: A record is created or updated
  • Set Entry Conditions: IsConverted = ‘true’
  • When to Run the Flow for Updated Records: Only when a record is updated to meet the condition requirements
  • Optimize the Flow for: Actions & Related Records

Save your Flow before going any further. Name it and add a description so that future admins know exactly the purpose of this Flow. 

Add a Get Element to get all Travel records linked to the Lead who triggered the Flow: 

  • Object: Travel
  • Filter: Lead = {!$Record.Id}
  • How Many Records to Store: All records
  • How to Store Record Data: Choose fields and assign variables (advanced)
    • Record Collection: create a Resource to store all records into a record collection: Variable of type Record & Allow multiple values (collection).
Picture of the Record Collection Variable
  • Facebook
  • Twitter
  • Gmail
  • LinkedIn
Picture of the Record Collection Variable
Picture of the Get Travel Records element
  • Facebook
  • Twitter
  • Gmail
  • LinkedIn
Picture of the Get Travel Records element

Add a Loop Element for the Flow to loop through the Travel records collection you just created.

In the Loop, add a first Assignment Element to assign to the current record: 

  • the Converted Opportunity Id into the Opportunity field: {!$Record.ConvertedOpportunityId}
  • the ‘true’ value into the “No UI Converted from Lead” field.
Picture of the Assignment Element
  • Facebook
  • Twitter
  • Gmail
  • LinkedIn
Picture of the Assignment Element

Add a second Assignment Element to add the current record to a List variable. Create that Resource Variable of type Record & Allow multiple values (collection).

Picture of the Assignment adding current record to a List
  • Facebook
  • Twitter
  • Gmail
  • LinkedIn
Picture of the Assignment adding current record to a List

Out of the Loop, add an Update Element. 

  • How to Find Records to Update and Set Their Values: Use the IDs and all field values from a record or record collection & add the variable created beforehand {!Var_TravelList}. 
Picture of the Update Records Element
  • Facebook
  • Twitter
  • Gmail
  • LinkedIn
Picture of the Update Records Element

The Flow in the end looks like: 

Picture of the Flow
  • Facebook
  • Twitter
  • Gmail
  • LinkedIn
Picture of the Flow

Test your Flow & Activate it!

  1. Create Custom Dynamic Lightning Page on the custom child Object

Once the Flow is Activated & working, we need to create a Custom Dynamic Lightning Page in order to hide & show the Lead and Opportunity lookup fields.

When creating a child record from a Parent record, the parent record is automatically added to the child relationship field. To control on Travel Create the relationship fields & hide them bot on the Create Page Layout, create a checkbox formula field checking if the record exist yet or not & add a description to explain this: 

Picture of the checkbox formula field
  • Facebook
  • Twitter
  • Gmail
  • LinkedIn
Picture of the checkbox formula field

Visibility filter on the Lead & Opportunity fields: 

  • Lead:
Picture of the Lead field visibility filters
  • Facebook
  • Twitter
  • Gmail
  • LinkedIn
Picture of the Lead field visibility filters
  • Opportunity:
Picture of the Opportunity field visibility filters
  • Facebook
  • Twitter
  • Gmail
  • LinkedIn
Picture of the Opportunity field visibility filters

Now, when creating a Travel record from either Lead or Opportunity, none of these fields are showing but they are filled in depending on where they are created from.

When looking at a Travel record, when at the Lead phase, only the Lead relationship field is visible. 

When converting a Lead to an Opportunity, the related Travel records are brought across to the converted Opportunity record, and only the Opportunity relationship field is visible.

If the Lead is converted without creating an Opportunity record, then related Travel records will not be lost but still exist with the (former) Lead (now Contact) record still populated. 

Hope that does the trick!

Share This