---
schema_version: "1"
id: 0365f9e5a9c72cccfe3d3abbd940ec87e83a916dff5dd247d92cf04a934b700c
title: Get Contacts and Leads from Email Addresses Action
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/platform/264-0-0/flow_ref_elements_actions_activities_match_contacts_leads.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.flow_ref_elements_actions_activities_match_contacts_leads.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 8e4ab66cca196fb24d88cc92f0a47455fa6ec35473bbface4b21ce9ca23e6f01
description: "This action matches email addresses to contact and lead records related to active user records. To be used in the Activities: Match Email to Records flow. Requires that Sync Email as Salesforce Activity is enabled in Einstein Activity Capture."
products:
  - Flow Builder
  - Salesforce Platform
release: "264"
---
# Get Contacts and Leads from Email Addresses Action

This action matches email addresses to contact and lead records related to active user records. To be used in the Activities: Match Email to Records flow. Requires that Sync Email as Salesforce Activity is enabled in Einstein Activity Capture.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: Lightning Experience</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available with Einstein Activity Capture Standard in Sales in <strong>Starter</strong>, <strong>Professional</strong>, and <strong>Enterprise</strong> Editions</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available with <strong>Unlimited</strong> Edition and <strong>Einstein 1 Sales</strong> Edition</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available with Einstein for Sales, which is included in <strong>Einstein 1 Sales</strong> Edition, and available for an extra cost in <strong>Enterprise</strong> and <strong>Unlimited</strong> Editions.</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available with Sales Engagement in Sales, which is included in <strong>Performance</strong> and <strong>Unlimited</strong> Editions, and available for an extra cost in <strong>Professional</strong> and <strong>Enterprise</strong> Editions.</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available with Revenue Intelligence, which is available for an extra cost in <strong>Enterprise</strong> and <strong>Unlimited</strong> Editions.</td></tr></tbody></table>

In Flow Builder, add an Action element to your flow. In the New Action window, search for Activities Match, and then select **Get Contacts and Leads from Email Addresses**.

## Set Input Values

Use values from earlier in the flow to set the inputs for the action.

 
| Field | Description |
| --- | --- |
| Account Field | The name of the field you use to identify partner accounts. Optional if Partner Accounts is `false`. This input is captured in the Uses Partner Accounts section of action properties in Flow Builder. |
| Comparison Operator | The comparison operator to determine a partner account. Valid values are Equals, Does Not Equal, Greater Than, Less Than, Greater Than or Equal, Less Than or Equal, Is Null, and Is Blank. Optional if Partner Accounts is `false`. This input is captured in the Uses Partner Accounts section of action properties in Flow Builder. |
| Email Addresses | Required. A collection of email addresses that don't have a corresponding active user record. |
| Partner Accounts | A Boolean value that indicates whether the business has partner accounts. The default value is`false`. This input is captured in the Uses Partner Accounts section of action properties in Flow Builder. |
| Users | Required. A collection of active user records to help determine related contact and lead records to match emails to. These user records contain an email address in the From, To, or CC of the email message. |
| Value | The value of the Account Field to identify a partner account. Optional if Partner Accounts is `false`. This input is captured in the Uses Partner Accounts section of action properties in Flow Builder. |

## Store Output Values

 
| Field | Description |
| --- | --- |
| Account Field | The name of the field you use to identify partner accounts. |
| Comparison Operator | The comparison operator to determine a partner account. Valid values are Equals, Does Not Equal, Greater Than, Less Than, Greater Than or Equal, Less Than or Equal, Is Null, and Is Blank. |
| Contacts | A collection of contact records that matched email addresses for contacts. |
| Leads | A collection of lead records that matched email addresses for leads. |
| Partner Accounts | A Boolean value that indicates whether the business has partner accounts. The default value is `false`. |
| Unmatched Email Addresses | A collection of email addresses that didn't match a contact or lead record. |
| Value | The value of the Account Field to identify a partner account. |

## Error Conditions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:50%">
          <col style="width:50%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d207577e336">Error Condition</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d207577e339">Description</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Error Condition" class="slds-cell-wrap" style="vertical-align:top;" headers="d207577e336 ">No Account Field</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d207577e339 ">
              <p>If Partner Accounts is <code>true</code>, specify an account field for
                partner account criteria.</p>
              <p style="margin-bottom:0;">Error Code: REQUIRED_FIELD_MISSING</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="Error Condition" class="slds-cell-wrap" style="vertical-align:top;" headers="d207577e336 ">No Comparison Operator</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d207577e339 ">
              <p>If Partner Accounts is <code>true</code>, specify a comparison operator for
                partner account criteria.</p>
              <p style="margin-bottom:0;">Error Code: REQUIRED_FIELD_MISSING</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="Error Condition" class="slds-cell-wrap" style="vertical-align:top;" headers="d207577e336 ">No Value</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d207577e339 ">
              <p>If Partner Accounts is <code>true</code>, specify a value for partner account
                criteria.</p>
              <p style="margin-bottom:0;">Error Code: REQUIRED_FIELD_MISSING</p>
            </td>

          </tr>
        </tbody>
      </table>

## Usage

To use this action, enable Sync Email as Salesforce Activity. The action is designed mainly to be used within the Activities: Match Email to Records flow.

## How It Works

This action uses as input the email message ID, email addresses that don’t match a user record, and user records that match an email address in From, To, or CC in the message. If you use partners in your sales process, the **Partner Accounts**, **Account Field**, **Comparison Operator**, and **Value** fields capture the criteria you use to indicate partner accounts. Set the values for these fields in the Uses Partner Accounts section of action properties in Flow Builder.

The action queries the **Email** field in Contact records to find the records that correspond to email addresses in action input. The list of user records is used to help as a tiebreaker when multiple contacts are found.

After finding contact records, the action queries the **Email** field in Lead records to match remaining email addresses to a lead. Email addresses that don’t match a contact or lead are stored in **Unmatched Email Addresses** in output.

## Contact Tiebreakers

If multiple contacts match an email address, the action follows this logic.

First, the action checks the **RecordTypeId** field on each of the contacts’ accounts. The action queries the **Name** field in the RecordType object. If the **Name** isn’t a partner for all matching contact records, then the action assumes that it’s a non-partner account. Similarly, if the **Name** is a partner for all matching contact records, then the action assumes that it’s a partner account. To determine the contact, the action evaluates these rules in order.

- If there are more than 10 contacts for the same email address, the action picks the contact with the most recent **LastActivityDate**. The action adds that contact to **Contacts** in action output.
- If a contact’s account owner matches a user record in **Users** in action input, then the action picks that contact and adds it to **Contacts** in action output.
- If a contact’s owner matches a user record in **Users** in action input, then the action picks that contact and adds it to **Contacts** in action output.
- If the prior rules didn’t result in a contact added to output, then the action picks the contact that was most recently modified. The action adds that contact to **Contacts** in action output.

Second, if matching contact records have a mix of partner and non-partner values for the **Name** field in the RecordType object, then the action evaluates these rules in order.

- If another contact matches a different email address in the email, and that contact belongs to a non-partner account, then the action ignores the non-partner contacts. To determine the contact, the action uses the partner contacts and evaluates them according to the contact tiebreaker rules. The action adds the result to **Contacts** in action output.
- If the prior rule didn’t result in a contact added to output, then the action uses the non-partner contacts and evaluates them according to the contact tiebreaker rules. The action adds the result to **Contacts** in action output.

## Lead Tiebreakers

If an email address didn’t match any contacts, then the action attempts to match it to a lead. If multiple leads match an email address, the action follows this logic.

- If a lead’s owner matches a user record in **Users** in action input, then the action picks that lead and adds it to **Leads** in action output.
- If the prior rule didn’t result in a lead added to output, then the action picks the lead that was most recently modified. The action adds that lead to **Leads** in action output.

## Limitations

This action is limited to usage within a flow. It can't be invoked through other methods such as Apex, REST API, Copilot, Prompt Studio, or Einstein Bots. While actions can typically be invoked through various frameworks like InvocableActionService, this specific action is restricted solely to Flow.

If the activityId field is empty when debugging this action, use the Developer Console to query StagedEmail for a value.

#### See Also

- [Test or Troubleshoot Flows with the Flow Builder Debugger](https://help.salesforce.com/s/articleView?id=platform.flow_test_debug.htm&release=264.0.0&type=5 "For flows that don't use Test Mode, use the Debug option to test or troubleshoot the flow. Review step-by-step details of how the flow runs and the path it takes.")
- [Flow Builder Debugger Considerations](https://help.salesforce.com/s/articleView?id=platform.flow_considerations_troubleshooting.htm&release=264.0.0&type=5 "Use these considerations when you debug a flow in Flow Builder.")