---
schema_version: "1"
id: 9039eb5fc3194ecf32b71b62908eccd8d250f53f7974a2729f0b056693636a01
title: Get Account and Opportunity 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_acct_oppty.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.flow_ref_elements_actions_activities_match_acct_oppty.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 023621652ee53574c40cf4e1eace7379a3645d0287c9edccda293ef2118131d5
description: "This action gets an account record associated with a contact or unmatched email address and also gets an opportunity record related to a contact. 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 Account and Opportunity from Email Addresses Action

This action gets an account record associated with a contact or unmatched email address and also gets an opportunity record related to a contact. 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 Account and Opportunity 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. |
| Activity Date | Required. The date and time of the activity. For email, it’s the date the email was sent. |
| 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. |
| Contacts | Required. A collection of contact records to get associated account and opportunity records for. |
| 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. |
| Unmatched Email Addresses | Optional. A collection of email addresses that don't have a corresponding active contact or active user record. |
| Users | Required. A collection of user records to get associated account and opportunity records for. |
| 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 | An account record that’s associated with one of the specified contacts or unmatched email addresses. |
| Opportunity | An opportunity record that’s associated with one of the specified contacts or the returned account record. If no opportunities are found, then it’s an opportunity record that’s owned by a user in the specified user collection. |
| Unmatched Email Addresses | A collection of email addresses that don't have a corresponding account or opportunity. |

## 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="d330851e314">Error Condition</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d330851e317">Description</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Error Condition" class="slds-cell-wrap" style="vertical-align:top;" headers="d330851e314 ">No Account Field</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d330851e317 ">
              <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="d330851e314 ">No Comparison Operator</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d330851e317 ">
              <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="d330851e314 ">No Value</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d330851e317 ">
              <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 date the email message was sent and user and contact records that match an email address in the From, To, or CC fields in the message. Optionally, input includes email addresses that don’t match a user or contact record. 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.

The action queries the **AccountId** field in contact records to find the account that corresponds to contacts in action input.

If no accounts were found, the action checks the domain of the **Website** field value of an account. If that domain matches the email domain of any address in **Unmatched Email Addresses** in input, then the action picks that account. If multiple accounts were found, then the action picks the account that has the most recent **LastActivityDate**.

After finding account records, the action queries the **ContactId** field in OpportunityContactRole records to match contacts to an opportunity. Only open opportunities that were created in the last year are included. If no opportunities were found, the action queries the **AccountId** field in opportunity records to find an opportunity with an account that matches **Account** in action output.

Email addresses that don’t have a corresponding account or opportunity are stored in **Unmatched Email Addresses** in output.

## Account Tiebreakers

If multiple accounts correspond to a contact’s email address, the action follows this logic.

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, then the action assumes that it’s a non-partner account. Similarly, if the **Name** is a partner, the action assumes that it’s a partner account. To determine the account, the action evaluates these rules in order.

- If contact records have a mix of partner and non-partner values for the **Name** field in the RecordType object, then the action picks the non-partner account. The action adds it to **Account** in action output.
- If the majority of contact records have the same account, then the action picks that account and adds it to **Account** in action output.
- If the prior rules didn’t result in an account added to output, then the action picks the account that has the most recent **LastActivityDate**. The action adds that account to **Account** in action output.

## Opportunity Tiebreakers

If multiple opportunities correspond to an email address, the action follows this logic. Opportunities that have been closed for 60 days or more past the **ActivityDate** aren’t considered for matching.

- If an opportunity’s owner matches a user record in **Users** in action input, then the action picks that opportunity and adds it to **Opportunity** in action output.
- If an opportunity’s account owner matches a user record in **Users** in action input, then the action picks that opportunity and adds it to **Opportunity** in action output.
- If the prior rules didn’t result in an opportunity added to output, then the action picks the opportunity with the most recent **LastActivityDate**. The action adds that opportunity to **Opportunity** 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.")