Match Leads to an Account Automatically with an Account Number

Often times companies have external sources of data coming into their system.  The most common scenario I see deals with leads.  Leads often times come in from a Web-to-Lead form.  Sometimes these forms might have some sort of Account Number associated to it, but forcing your customers or prospects to use the correct Account Name in Salesforce is next to impossible.   Ideally we could automatically search through our Accounts to see if we have a match on the Account Number and update the Lead’s Company Name with the Account Name.  This would streamline our conversion process as our Account Name would be an exact match.  Well, that actually is something that we can do with an Autolaunched Flow!  Lets give it a shot!

If you are new to Flow and get lost along the way during this post, please take a look at these three posts in my Learning Flow series:

  1. Record Lookup Elements
  2. Record Update Elements
  3. Decision Elements

Navigate over to create a new Flow. (Setup | Create | Workflows & Approvals | Flows)

New Flow

The first step is going to be grabbing our Record Lookup.


Lets create a variable called var_AccountNumber.  This is where we will store the Account Number variable from our Lead, and use it to search through all of our Accounts in our Record Lookup’s criteria.



Next, we need to assume that we have found an Account that is a match.  In this example, we are wanting to now update our Lead’s Company Name with the matched Account Name.  That means, we need to assign the Name field from the Account into a variable.  This allows us to use the value in another element in our Flow.



Now, what we want to do is to make sure we have our “Assign null values to the variable(s) if no records are found” marked as TRUE.


Hit OK and then lets set this element as the Start element for our Flow.


This next step is a ‘SalesforceSidekick’ Flow Best Practice.  I typically don’t put it into my examples, because the majority of my examples are coming over in defined situations.  However, in this situation we are not certain that every Lead coming in with an Account Number will have a match, so we need to put in a Decision to validate that we in fact did find a match.

It’s actually extremely easy to do this, and it doesn’t take too much more time.  I now do this after every Lookup record that I have.  All we are going to do is checking if the variable(s) that we found in our last Lookup are Null or not.


Notice, we are using ‘is null’ as our operator and the standard value {!$GlobalConstant.False}.  So that means, if our Account Name has a value it is not null, and we should continue on in our Flow.  If it is null, then we will leave it as an un-connected part of the Decision and that record will exit as if nothing ever happened!


Alright, so lets proceed on and assume we have a match. We need to setup a Record Update to our Lead and update the Company.


In our Process Builder we will be passing in the Lead Id (along with the Account Number).  We need to have the Lead Id stored in a variable, so that we can reference it as our criteria in this Record Update to pull up the correct Lead record.  So lets create the variable var_LeadId.


Set the Criteria to be the Lead Id = our var_LeadId.


Make sure we have our Company = var_AccountName.


Great, we’re done with our last element in the Flow.  Let’s connect the Flow together.  Remember, we’re sending the YES part of our Decision on to this Record Update, and the NO part is not being connected to anything.

Completed Flow

Now lets save our Flow and Activate it!  Remember to activate your Flow.  If you don’t, the Process Builder won’t be able to find it!

Save Flow


To make this an Autolaunched Flow, we need to have it launched by a Process Builder, so lets head over and create a new one! (Setup | Create | Workflows & Approvals | Process Builder)


We want our Process Builder to run from the Lead Object.  This is because our Lead Object is where the transaction is occurring.  A Web-to-Lead form happens, and with that we want the Flow to fire and see if we have a match.


Lets add in our Criteria for the Process Builder.  We want to fire this only when our Account Number field on the Lead is not null.  We have no use for our Flow without this field being populated anyways!  Notice, at the bottom I expanded the Advanced section and checked the box.  This means, in short, that I only want this Process Builder to fire once.  If you have questions on this part, read the information bubble to the right.


Now we get to add in an Action with the type of Flows to our Process Builder.


Lets give our Action a Name, and then go down and set our Flow’s pre-set variables that are being passed in through our Process Builder.  In this example we are passing in the values to our var_LeadId and var_AccountNumber.


Hit Save, and then hit Activate up in the top right corner.  Now treat yourself to a nice cuppa (or the drink of your choosing) and enjoy your accomplishment of completing this awesome Autolaunched Flow!

10 thoughts on “Match Leads to an Account Automatically with an Account Number

  1. Jen January 23, 2017 / 8:18 pm

    Great article! Do you know if it is possible to do something similar match a lead to an account based on the account website? This would have to use the domain from the lead’s email address to see if it matches the account website.


    • David Litton January 23, 2017 / 8:24 pm

      Thanks Jen! Yes, you can do it on any field that they share. The easiest way would be to probably have a formula field on the Account that shows just that domain, and then a formula field on the Lead that also just shows the domain… then do the match on those two formula fields.

      If you have a high volume of Leads or Accounts, you’ll want to make sure you index the formulas.


      • jenstretch January 24, 2017 / 3:59 am

        Hi David – I created the custom domain fields and have set up the Flow and Process Builder. The logic is if the domains match, then I would like to populate a custom field on the lead for the Account Type (client, prospect, etc). However, I’m not seeing the field update.

        Any chance you want to take a look at some screenshots of what I’ve set up to see if you can figure out what I’m missing?



      • Jen January 24, 2017 / 4:01 am

        Hi David – I created the custom domain fields and have set up the Flow and Process Builder. The logic is if the domains match, then I would like to populate a custom field on the lead for the Account Type (client, prospect, etc). However, I’m not seeing the field update.

        Any chance you want to take a look at some screenshots of what I’ve set up to see if you can figure out what I’m missing?



  2. Anonymous April 17, 2017 / 5:58 pm

    Thanks for this detailed article. Do you know if there is a way to preview the leads and accounts that the flow will affect prior to activation?


    • David Litton April 18, 2017 / 7:12 pm

      You can’t do a preview with Auto-Launched. You’d be able to maybe do it with a Flow Interface through a button the User clicks? They select if they want to confirm the change before it saves to the record.


  3. Christina April 18, 2017 / 3:58 pm

    Hi David, I activated the flow using the instructions you provided but when I got to the Process Builder, when I try to build the criteria “Account Number is not NULL” I don’t see an option for “Account Number.” Can you help?


    • David Litton April 18, 2017 / 7:14 pm

      You need to ensure that you have the Field Level Security turned on for the field. If you’re using the default Account Number field, I think it defaults to hidden to all Users. Let me know if after ensuring FLS is there it doesn’t show up still


      • Christina April 18, 2017 / 7:50 pm

        When you refer to enabling field security for the field, do you mean it needs to be invisible or read only? Currently it’s on Visible and Read Only.


      • Christina April 18, 2017 / 7:57 pm

        David, I actually figured out the problem related to the Account Number. Due to a third party service we use (DataFox), the account fields were located in a different folder which I was confused by. Anyhow, while I’m able to locate the field, I don’t see any options to set the field variables. See screenshot here:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s