Relate Leads to Accounts Using Salesforce Flow

Business Problem

A common issue sales reps run into in Salesforce is the existence of leads in their database that are current customers. They end up calling the prospect trying to pitch their product and the person tells them "We are already a customer of yours". Few things are worse for a sales person than cold calling your existing customers. Leads come into Salesforce from web forms, white paper downloads, etc. and nothing is checking for whether they are a current customer or not.

We have developed an AppExchange package that relates a Lead record to an Account record by looking for a match between the Lead's email address domain and the Account's website domain. While this doesn't find all of the leads that could exist for your Accounts, it does help. Here are the components in the package:

  • Account | Related Leads Based on Website Email Domain (Record-Triggered Flow)
  • Lead | Relate to Account by Email Domain Flow (Record-Triggered Flow)
  • Account - Lead | Relate Leads to Accounts (Record-Triggered Flow)
  • Account (Custom field on the Lead object) - this is a lookup field to the Account object.
  • Email Domain (Custom field on the Lead object) - this is a formula field
  • Website Domain (Custom field on the Account object)
  • Website Domain and Path (Custom field on the Account object)

How to Configure the App

  1. Install the AppExchange package into a sandbox environment.
  2. Go to SetupFlows and Activate the following flows:

    • Account | Related Leads Based on Website Email Domain
    • Lead | Relate to Account by Email Domain Flow
    • Account - Lead | Relate Leads to Accounts

  3. Update field level security for the fields for the necessary profiles.
  4. Go to Leads Page Layouts and add the Account field to your Lead page layouts.
  5. Go to Accounts Page Layouts and add the Leads related list to your Account page layouts.

That's it, you are ready to test out the app!

Website Domain Fields & Formulas

Now we have to give credit to Walter Pelowski from the Salesforce developer community for the formulas he created for the fields called Website Domain and Website Domain and Path - you can see his post here. Thanks Walter!

We can see how amazing his formulas are, they solve for every scenario we have tested with. Here you can see it in action, we have Website = www.bluninjas.com/blog and the Domain correctly shows bluninjas.com.

How to see if a Lead is related to an Account

  • When a new Lead is created in Salesforce or the Lead's email address is changed, the flow called Lead | Relate to Account by Email Domain Flow is triggered. This flow invokes the subflow called Account - Lead | Relate Leads to Accounts. The flow looks for existing accounts records where the value in the Website Domain field matches the Email Domain field on the Lead.  If it finds multiple Accounts with the same domain, it sorts the list by Last Activity Date and the most recent date is chosen as the Account to relate to the Lead. The flow then updates the Account field on the Lead.
  • Here is what it looks like from the Lead:

  • Here is what it looks like from the Account: Leads are shown in a related list on the Account page.

  • Now that your Lead is related to the Account, you can do things to help your sales reps out. You can show/hide text based on whether the Account is a customer so they do not call them. Or you could take it one step further and automatically convert the lead to a contact under the customer's Account record.

What Happens if an Account's Website Changes?

If you change the value of the Website on the Account, the flow called Account | Related Leads Based on Website Email Domain is triggered and it will invoke the sub-flow called Account - Lead | Relate Leads to Accounts. The flow will now go down a different path and will check to see if the current Leads related to the Account have an email address domain that matches the website domain of the Account. If it doesn't match, the Account field on the Lead is updated to be blank. Then the flow looks through the other Leads and checks for matches. When it finds a match, it updates the Account field on the Lead record.

Now you are ready to move onto configuring the 2nd part of this app - Mass convert leads from the Account page. See this article for complete instructions.

For any questions, comments, concerns – let us know in the comment section below!
We would love to hear from you!

Share This Story, Choose Your Platform!

About the Author

Anjana Prakash

Anjana is a certified Salesforce developer and Technical Lead at Blu Ninjas. A passionate programmer with ninja skills in multiple programming languages, she has been solving challenging problems in a variety of industries on the Salesforce platform for more than 10 years.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top