How to automatically link a Contact or Lead to its Account in Salesforce
Learn how to build a Salesforce Flow that links a Contact or Lead to the correct Account by matching email domain to website domain.
Why you need this
Firmable's push to Salesforce doesn't automatically link a new Contact or Lead to its parent Account. This Flow closes that gap by matching the domain of the Contact's email address to the Website field on the Account, and linking them automatically before the record saves.
Note: this logic applies to both Leads and Contacts, but you'll need to build a separate Flow for each object, one for Contact, one for Lead, using the same steps below with the object swapped.
Flow type
- Type: Record-Triggered Flow
- Object: Contact (build a second one on Lead for full coverage)
- Trigger point: Before Insert
- Action: updates the Contact.AccountId field with the matching Account
A note on which field to match on
Website domain is the recommended match field here, Firmable pushes it consistently and most companies have a genuinely unique domain. The same logic works with other unique company identifiers too, if you'd rather match on something else, for example a company LinkedIn URL or ABN. To swap it, change the formula in Step 3 to extract or reference that field instead of the email domain, and update the filter condition in Step 4 to match against it. The rest of the Flow (Step 5 onward) stays the same.
Prerequisites
- The Website field on the Account object is populated
- Contacts have valid, real domain names in their email addresses
How to build it
Step 1: Create a new Flow
- In Salesforce, go to Setup, search for and select Flows, click New Flow
- Choose Record-Triggered Flow, click Create
Step 2: Configure the Flow start
- Object: Contact
- Trigger the Flow when: A record is created
- Run the Flow: Before the record is saved
Step 3: Extract the domain from the Contact's email
- Add a new Formula resource, API name ExtractedEmailDomain, data type Text
- Formula: LOWER(RIGHT(Contact.Email, LEN(Contact.Email) - FIND("@", Contact.Email)))
- This extracts everything after @ and converts it to lowercase
Step 4: Get matching Accounts
- Add a Get Records element, label GetMatchingAccount, object Account
- Filter: Website contains ExtractedEmailDomain (adjust the condition to ignore a leading "www.")
- How many records to store: only the first record
Step 5: Check if a match was found
- Add a Decision element, label CheckIfAccountExists
- Outcome (yes): label AccountFound, condition GetMatchingAccount is not null
- Default outcome: No Matching Account
Step 6: Update the Contact
- Under the AccountFound path, add an Assignment element, label AssignAccountToContact
- Variable: $Record (the triggering Contact)
- Field to update: AccountId, value: GetMatchingAccount.Id
Step 7: Connect the elements
- Start → GetMatchingAccount → CheckIfAccountExists → (AccountFound path) → AssignAccountToContact
Step 8: Save and activate
- Save, label it something like LinkContactToAccountByEmailDomain, then click Activate
Testing
Create a new Contact with an email domain matching an existing Account's website, save it, and confirm it's automatically linked to that Account.
Things to watch for
- Multiple Accounts sharing the same domain will only link to the first match, review these manually rather than relying on the Flow
- On CRMs with a very large Account volume, keep an eye on performance with high Account counts sharing similar domains
Frequently asked questions
Does this work for existing Contacts, or only new ones? As built, this triggers Before Insert, so it only runs on new Contact creation. Updating existing unlinked Contacts needs a one-off manual review or a separate scheduled Flow.
Do I need this for Leads too? Yes, build an identical Flow on the Lead object, same logic, same steps.
We hope this article has helped you set up automatic Contact-to-Account linking in Salesforce. If you have any other questions, don't hesitate to contact us at support@firmable.com.