Loading

Customize Salesforce Email Matching with Flow Use Cases for Einstein Activity Capture

Дата публикации: Sep 22, 2026
Описание

This document will walk through several use cases and setup steps for the Customize Flows to Match Synced Email to Related Activity feature that is available in the Summer 25 release.

Important Note: Adding complex logic to the Activities Flow can potentially affect email sync times. We generally recommend using Apex triggers where possible for custom matching logic. Review full considerations here.

Решение

This article walks through several use cases and setup steps for the Customize Flows to Match Synced Email to Related Activity feature, showing how to combine Flow with Apex triggers to control how Einstein Activity Capture emails are matched, blocked, or redacted.

Use Case 1a: Skip Matching an Email to an Opportunity and Match to a Custom Object Instead

Combine a Flow change with a post-trigger to match an email to a custom object using email subject content.

Step 1: Open the default "Activities: Match Email to Records" Flow. Then "Save as New Flow". Name your new Flow.

Activities: Match Email to Records Flow open in Flow Builder before saving as a new Flow

Step 2: Open the last action "Create Email Activity with Associations". Disable the "Opportunity" input value. Save and activate.

Create Email Activity with Associations action with the Opportunity input value disabled

Step 3: Create new trigger on EmailMessage to match to Custom Object.

EXAMPLE TRIGGER:

trigger EmailMessagetoCustomOpportunityMappingSimplified on EmailMessage (after insert) {
    List<EmailMessage> emailsToUpdate = new List<EmailMessage>();

    for (EmailMessage em : Trigger.new) {
        if (em.Incoming && (em.Source == 'Einstein Activity Capture' || em.Source == 'Einstein Activity Capture Limited') && String.isNotBlank(em.Subject)) {
            Matcher matcher = Pattern.compile('(?i)recruitment[\s_-]*id[:\s]*([0-9]+)').matcher(em.Subject);
            if (matcher.find()) {
                String recruitmentId = matcher.group(1);

                // Find existing Custom Opportunity
                List<Custom_Opportunity__c> opps = [
                    SELECT Id FROM Custom_Opportunity__c
                    WHERE RecruitmentId__c = :recruitmentId
                    LIMIT 1
                ];

                if (!opps.isEmpty()) {
                    emailsToUpdate.add(new EmailMessage(
                        Id = em.Id,
                        RelatedToId = opps[0].Id
                    ));
                }
            }
        }
    }

    if (!emailsToUpdate.isEmpty()) {
        update emailsToUpdate;
    }
}

This trigger looks for a "Recruitment ID" pattern in the incoming email's subject line, finds the matching Custom_Opportunity__c record by that ID, and relates the email to it.

How Does It Work?

Example setup for above trigger:

  1. Admin creates custom object:

Custom object creation screen for the Custom Opportunity object

  1. Admin edits 'Name' field to "RecruitmentId"
  2. Admin adds custom text field to "Recruitment Id"

Custom field setup showing the Recruitment Id text field added to the custom object

Test email sent containing "Recruitment ID 12345" in subject; matches to Recruitment Id record.

Email successfully matched to the Custom Opportunity record with Recruitment ID 12345

Use Case 1b: Match to Custom Object Using Email Body Content

The previous example (Use Case 1a) uses email subject to match recruitment ID. Below is a sample trigger for using email subject and body content.

EXAMPLE TRIGGER:

trigger EmailMessagetoCustomOpportunityMappingNew on EmailMessage (after insert) {
    List<EmailMessage> emailsToUpdate = new List<EmailMessage>();

    for (EmailMessage em : Trigger.new) {
        if (em.Incoming && em.Source == 'Einstein Activity Capture' || em.Source == 'Einstein Activity Capture Limited') {
            // Combine Subject and Body for regex matching
            String combinedText = (em.Subject != null ? em.Subject : '') + ' ' +
                (em.TextBody != null ? em.TextBody : '') + ' ' +
                (em.HtmlBody != null ? em.HtmlBody : '');

            Matcher matcher = Pattern.compile('(?i)recruitment[\s_-]*id[:\s]*([0-9]+)').matcher(combinedText);
            if (matcher.find()) {
                String recruitmentId = matcher.group(1);

                // Find existing Custom Opportunity
                Custom_Opportunity__c opp = [
                    SELECT Id FROM Custom_Opportunity__c
                    WHERE RecruitmentId__c = :recruitmentId
                    LIMIT 1
                ];

                if (opp != null) {
                    emailsToUpdate.add(new EmailMessage(
                        Id = em.Id,
                        RelatedToId = opp.Id
                    ));
                }
            }
        }
    }

    if (!emailsToUpdate.isEmpty()) {
        update emailsToUpdate;
    }
}

This trigger extends the Use Case 1a logic by searching the Recruitment ID pattern across the subject, plain-text body, and HTML body combined, rather than the subject alone, before relating the email to the matching Custom Opportunity record.

Use Case 2: Block Email from Logging if It Contains a Certain Word

Important Note: The staged email is still stored for 30 days even when the flow is bypassed. The staged email ID is available to admins during those 30 days, but no other email data is accessible.

  1. Add a decision element after the Flow start.
  2. Add conditions for emails that should be skipped for matching, which will then END the flow. If conditions are not met, the Flow runs normally.
    1. In the example below, the email is skipped for matching if the subject, HTML body, or text body contain the word "sunshine."

Decision element in Flow Builder checking whether the email subject or body contains the word sunshine, ending the flow if true

This decision element inspects the email's subject, HTML body, and text body for the specified keyword; when found, the Flow ends immediately so the email is never matched to a record.

Use Case 3: Redact Email Body/Subject if It Contains a Certain Word

Important Note: This trigger will edit the contents of the email message. The customer's email service should always be the primary source of truth for email content.

EXAMPLE TRIGGER:

trigger RedactSensitiveEmail on EmailMessage (after insert) {

    String keyword = 'goldfish';
    List<EmailMessage> emailsToUpdate = new List<EmailMessage>();

    for (EmailMessage em : Trigger.new) {
        // Only handle EAC or EAC Limited sources
        if ((em.Source == 'Einstein Activity Capture' || em.Source == 'Einstein Activity Capture Limited')) {
            Boolean redact = false;

            if (!String.isEmpty(em.Subject) && em.Subject.toLowerCase().contains(keyword)) {
                redact = true;
            } else if (!String.isEmpty(em.TextBody) && em.TextBody.toLowerCase().contains(keyword)) {
                redact = true;
            } else if (!String.isEmpty(em.HtmlBody) && em.HtmlBody.toLowerCase().contains(keyword)) {
                redact = true;
            }

            if (redact) {
                emailsToUpdate.add(new EmailMessage(
                    Id = em.Id,
                    Subject = 'redacted',
                    TextBody = 'redacted',
                    HtmlBody = 'redacted'
                ));
            }
        }
    }

    if (!emailsToUpdate.isEmpty()) {
        update emailsToUpdate;
    }
}

How Does It Work?

The trigger looks for a specific word in the email content (in the case above, the word is "goldfish"). The trigger then replaces the subject and body with the word "redacted".

Номер статьи базы знаний

005134931

 
Загрузка
Salesforce Help | Article