Purpose: This article provides step-by-step instructions on creating a Salesforce Flow to automatically populate the Related To field on an Event record. The flow will check if an Opportunity exists for the Account assigned to the Event and, if found, will populate the Related To field with that Opportunity.
Step-by-Step Instructions
Step 1: Set Up a New Record-Triggered Flow
- Go to Setup > Flow > New Flow.
- Choose Record-Triggered Flow and set the object to Event.
- Configure the flow to trigger When a record is created or updated.
- Save the flow with a descriptive name, such as "Auto-Populate Related To on Event."
Step 2: Add Entry Conditions
Define when this flow should run by adding the following entry conditions:
-
In Set Entry Conditions:
- Click + Add Condition:
- Field: Select
AccountId
(the Account field on the Event). - Operator: Set to Is Null.
- Value: Set to False (indicating that the Account field is not empty).
- Description: Event is connected to an account
- Field: Select
- Click + Add Condition again:
- Field: Select
WhatId
(the Related To field on the Event). - Operator: Set to Is Null.
- Value: Set to True (indicating that the Related To field is empty).
- Description: Event doesn't have an opp related to it already
- Field: Select
- Click + Add Condition:
-
Leave Filter Logic as
1 AND 2
-
Under Optimize the Flow for, choose Actions and Related Records.
Step 3: Get Related Opportunities
- Add a Get Records element to retrieve Opportunities related to the Account on the Event.
- Label: "Get Opportunities for Account."
- Object: Opportunity.
- Condition Requirements: All Conditions Are Met (AND)
- Filter Conditions 1:
- Field: Select
AccountId
. - Operator: Equals.
- Value:
{!$Record.AccountId}
(the Account from the Event). - Description: Account Id on Opportunity matches Account id on event.
- Field: Select
- Filter Conditions 2:
- Field: Select
IsClosed
. - Operator: Equals.
- Value:
False
- Description: Opportunity is open
- Field: Select
- Filter Conditions 3:
- Field: Select
OwnerId
. - Operator: Equals.
- Value:
{!$Record.Owner:User.Id}
- Description: Owner of the opportunity matches the owner of the event
- Field: Select
- Sort Order: Sort by
CloseDate
(optional). - Get Only the First Record: Select this option if you want the most recent Opportunity.
Step 4: Check if an Opportunity was Found
- Add a Decision element after the "Get Opportunities for Account" element to check if any Opportunity was found.
- Label: "Check if Opportunity Found."
- Create two outcomes:
- Outcome 1: Opportunity Found
- Condition:
{!Get_Opportunities_for_Account}
Is Null False - Descripton: This outcome will run if an Opportunity exists for the Account.
- Condition:
- Outcome 2: No Opportunity Found
- Condition:
{!Get_Opportunities_for_Account}
Is Null True - Descripton: This outcome will handle cases where no matching Opportunity exists.
- Condition:
- Outcome 1: Opportunity Found
Step 5: Update the Event Record
If an Opportunity was found, proceed with the following steps:
-
Under the Opportunity Found outcome path, add an Update Records element.
- Label: "Update Event with Opportunity."
- Set Specify Conditions to Identify Records, and Set Fields Individually.
- Object to Update: Event.
- Conditions:
- Field:
Id
. - Operator: Equals.
- Value:
{!$Record.Id}
(the triggering Event record).
- Field:
- Set Field Values for the Event Record:
- Field: Related To (
WhatId
). - Value:
{!Get_Opportunities_for_Account.Id}
(the Opportunity ID found in Step 3).
- Field: Related To (
2. Save the element configuration.
Completed Flow Snapshot
Final Steps
- Activate the flow once all elements are configured and saved.
- Test the flow by creating or updating an Event record with:
- A contact assigned. (Salesforce will roll the event up to the connected account which is where the flow will be looking)
- An empty Related To field.
Expected Result: The Related To field on the Event record will be populated with the Opportunity associated with the same Account.
Troubleshooting Tips:
- If you see the error "Invalid condition logic," ensure your Filter Logic field in Update Records is blank.
- Double-check all Field, Operator, and Value settings, especially for entry conditions and decisions.
Article Summary: This flow automates the population of the Related To field on Event records by checking for a related Opportunity under the same Account. This guide walks through each step of creating, configuring, and testing the flow for a seamless automation setup.