Record Trigger Scenario 2
Your organization manages Accounts, Contacts, and Opportunities for sales operations. You want to automate the process of notifying the Account Owner when a Contact’s ‘StatusChange’ custom field changes to ‘Inactive.’ Additionally, you want to update the ‘Opportunity Stage’ of all related Opportunities to ‘On Hold’ when this Contact’s status changes. Explain how you would design a Flow to accomplish this.
Answer
Let’s focus on pattern to solve this scenario so that we can solve flow questions effectively.
1. Understand the Requirement:
– Trigger Point: When a Contact’s ‘StatusChange’ changes to ‘Inactive.
– Output: Automate notification to the Account Owner and update Opportunity Stages.
2. Break It Down:
– Data retrieval: Identify the Contact’s Account and related Opportunities.
– Notifications: Send a notification to the Account Owner.
– Update: Update Opportunity Stages based on the Contact’s status change.
3. Visualize the Flow:
– Sequence:
– Start the Flow when a Contact’s ‘Status’ changes to ‘Inactive.’
– Retrieve the Contact’s Account and related Opportunities.
– Send a notification to the Account Owner.
– Update the ‘Opportunity Stage’ on related Opportunities.
4. Design the Flow:
– Elements:
– “Record Triggered Flow” to initiate the Flow on Contact status change. We will select when record is updated as flow should run when contact ‘statuschange’ field is changed to inactive.
– “Decision Element” check whether casestatus field is active or not
– “Get Records” element to fetch the Contact’s Account. For this filter should be to fetch account which has id same as contact’s accountid
– Send email notification to the Account Owner.
—
Write the email. When it comes to drafting the content of your email, you have three available options:
Option 1: As of Salesforce’s Summer ‘23 release, you can use email templates with the Send Email action. You can do this by toggling Email Template ID to On and entering the ID of the email template you want to use. To find this ID, navigate to your email template from the Lightning Email Templates in your apps or the Classic Email Template page in setup. Then copy the 15-character string from the URL and paste it into your flow as the Email Template ID.
Option 2: Store the body of your email in a text template. To do this, toggle the Body switch On. Next, select New Resource from the menu and choose Text Template. Give the template an API name and type the body of your email. You can enter custom resources from the menu above the text box. This way, you can include both static text and personalized information for the lead. Once your template is complete, click Done.
- Now that we have the content of our email written, it’s time to determine who it is going to. Toggle the recipient list On and enter {!$Record.Email}. Now, the email address tied to the Lead object will automatically become the recipient.
- Another new feature of the Summer ‘23 release of Salesforce is the ability to log emails sent with the Send Email action. This means you can automatically update records when an email is sent, so you have a clear timeline of communication stored directly within the object record. To do this, toggle the Log Email on Send option On and set the value as {!$GlobalConstant.True}.
- Toggle Recipient ID to On and enter {!$Record.Id} Now, the recipient record will automatically update to show when they were contacted, what the email said, and even when they opened it.
Next, toggle Rich-Text-Formatted Body On. From the drop-down menu, select {!$GlobalConstant.True}. This ensures our email formatting remains consistent.
Last, toggle the Subject value to On and type your subject in the box. You can skip this step if you are using an Email Template ID.
– “Update Records” element to update Opportunity Stages.
5. Test Scenario:
– Change the ‘StatusChange’ of a Contact to ‘Inactive’ and verify that the Flow correctly notifies the Account Owner and updates Opportunity Stages to ‘On Hold’.
Output