Effortless Automation: Email Notifications for Salesforce Cases via Email-to-Case, Flow, and Email Templates

Himanshu Varshney
Senior Salesforce Developer
December 15, 2023

SalesforceEmailFlowsBlog

Create an Email Template:

In Salesforce, navigate to Setup. In the Quick Find box, enter "Classic Email Templates" or "Lightning Email Templates" based on your Salesforce version. Create a new Email Template or use an existing one that suits your notification requirements.


Create a Flow:

Go to Setup.

In the Quick Find box, enter "Flows" and select "Flows."

Create a new Flow by clicking on "New Flow."

Use the Flow Designer to build your flow. Here's a simplified example of a flow that sends an email notification:

+---------------------+
| Start               |
| (Record Trigger)   |
+---------------------+
         |
         V
+---------------------+
| Record Lookup       |
| (Lookup Case)       |
+---------------------+
         |
         V
+---------------------+
| Decision            |
| (Is Case Found?)    |
+---------------------+
|                     |
| Yes                 | No
|                     |
V                     V
+---------------------+        +-----------------------+
| Send Email          |--------| Create Case Record   |
| (Use Email Template)|        |                       |
+---------------------+        +-----------------------+

The Flow should start with a Record Trigger for the Case object.

Add a Record Lookup to check if the case already exists (using criteria like Email Subject, etc.).

Use a Decision element to check if the case was found.

If the case is found, proceed to the Send Email element, using the Email Template you created.


Activate the Flow:

Once you've created and tested your Flow, activate it. Configure Email-to-Case:

In Salesforce, navigate to Setup. In the Quick Find box, enter "Email-to-Case." Configure your Email-to-Case settings to use the Flow you created for the "On Create" trigger.


Test:

Create a test case by sending an email to your designated Email-to-Case email address. Ensure that the email creates a new case and triggers the Flow. Here's an example code snippet for sending an email in the Flow. Note that the actual code may vary based on your specific requirements and the complexity of your email template:

// Apex Class for sending an email in Flow
public class FlowEmailNotification {

    // Method to send email using the specified email template
    public static void sendEmailNotification(Id caseId, Id emailTemplateId) {
        // Load the case record
        Case myCase = [SELECT Id, Subject, Description, ... FROM Case WHERE Id = :caseId LIMIT 1];

        // Load the email template
        EmailTemplate emailTemplate = [SELECT Id, Subject, HtmlValue, Body FROM EmailTemplate WHERE Id = :emailTemplateId LIMIT 1];

        // Create an Email Message
        Messaging.SingleEmailMessage emailMessage = new Messaging.SingleEmailMessage();
        emailMessage.setSubject(emailTemplate.Subject);
        emailMessage.setHtmlBody(emailTemplate.HtmlValue);
        emailMessage.setPlainTextBody(emailTemplate.Body);
        emailMessage.setToAddresses(new String[] { 'recipient@example.com' }); // Replace with the recipient's email address

        // Attach the case information to the email
        emailMessage.setWhatId(myCase.Id);

        // Send the email
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { emailMessage });
    }
}

In your Flow, you would use an "Apex Action" to invoke this Apex class and pass the necessary parameters such as the caseId and emailTemplateId.

Remember to adapt the code to your specific requirements, including handling errors and customizing the email content based on your Email Template structure. Additionally, ensure that your Salesforce user has the necessary permissions to execute Apex and send emails.


Now, for the second part, we will send an email notification whenever a case is resolved via Email-to-Case in Salesforce using Flow and an Email Template. You can follow a similar approach as mentioned before. However, this time, you'll need to trigger the Flow when the case is resolved. Here's a step-by-step guide:


Create an Email Template:

In Salesforce, navigate to Setup. In the Quick Find box, enter "Classic Email Templates" or "Lightning Email Templates" based on your Salesforce version. Create a new Email Template or use an existing one for the resolution notification.


Create a Flow:

Go to Setup.

In the Quick Find box, enter "Flows" and select "Flows."

Create a new Flow by clicking on "New Flow."

Use the Flow Designer to build your flow. Here's a simplified example of a flow that sends an email notification when a case is resolved:

+---------------------+
| Start               |
| (Record Trigger)   |
+---------------------+
         |
         V
+---------------------+
| Record Lookup       |
| (Lookup Case)       |
+---------------------+
         |
         V
+---------------------+
| Decision            |
| (Is Case Resolved?) |
+---------------------+
|                     |
| Yes                 | No
|                     |
V                     V
+---------------------+        +-----------------------+
| Send Email          |--------| Update Case (Optional)|
| (Use Email Template)|        |                       |
+---------------------+        +-----------------------+

The Flow should start with a Record Trigger for the Case object.

Add a Record Lookup to check if the case is resolved (use the status field or any custom field that indicates resolution).

Use a Decision element to check if the case is resolved.

If the case is resolved, proceed to the Send Email element, using the Email Template you created.

Optionally, you can add an Update Case element to update the case record, such as setting a "Notification Sent" flag.


Activate the Flow:

Once you've created and tested your Flow, activate it. Configure Email-to-Case:

In Salesforce, navigate to Setup. In the Quick Find box, enter "Email-to-Case." Configure your Email-to-Case settings to use the Flow you created for the "On Case Resolution" trigger.

Test:

Resolve a test case either manually or through your Email-to-Case process. Ensure that the resolution triggers the Flow and the email notification is sent.

For the code snippet, you can use a similar Apex class as before with a method tailored for the resolution notification. Here's an example:

// Apex Class for sending an email on case resolution in Flow
public class FlowEmailOnResolution {

    // Method to send email notification on case resolution
    public static void sendResolutionNotification(Id caseId, Id emailTemplateId) {
        // Load the case record
        Case myCase = [SELECT Id, Subject, Description, ... FROM Case WHERE Id = :caseId LIMIT 1];

        // Load the email template
        EmailTemplate emailTemplate = [SELECT Id, Subject, HtmlValue, Body FROM EmailTemplate WHERE Id = :emailTemplateId LIMIT 1];

        // Create an Email Message
        Messaging.SingleEmailMessage emailMessage = new Messaging.SingleEmailMessage();
        emailMessage.setSubject(emailTemplate.Subject);
        emailMessage.setHtmlBody(emailTemplate.HtmlValue);
        emailMessage.setPlainTextBody(emailTemplate.Body);
        emailMessage.setToAddresses(new String[] { 'recipient@example.com' }); // Replace with the recipient's email address

        // Attach the case information to the email
        emailMessage.setWhatId(myCase.Id);

        // Send the email
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { emailMessage });
    }
}

As before, you would use an "Apex Action" in your Flow to invoke this Apex class and pass the necessary parameters such as the caseId and emailTemplateId. Customize the code based on your specific requirements and the structure of your Email Template.

Share this article:
View all articles

Related Articles

Reducing Operational Costs with AI Chatbots: A Smart Business Move featured image
December 29, 2025
Operational costs often rise because teams spend too much time on repetitive, low-value work. This article explains how AI chatbots reduce those costs by deflecting routine requests, shortening support interactions, automating back-and-forth workflows, and allowing businesses to scale without hiring linearly. It also shows how Anablock designs cost-effective AI chatbot solutions that deliver measurable automation savings while improving customer experience.
Cross-Industry Applications of AI Chatbots featured image
December 23, 2025
AI chatbots are no longer limited to basic FAQs. This article explores how the same conversational AI technology is being applied across healthcare, real estate, finance, hospitality, e-commerce, SaaS, and internal operations. You will see practical examples of how businesses use chatbots to automate repetitive tasks, improve responsiveness, and connect systems across industries, along with guidance on choosing the right starting use case.
10 CRM Admin Tasks You Should Automate with AI featured image
December 22, 2025
If being a CRM admin feels like nonstop cleanup, this article is for you. It breaks down ten time consuming CRM admin tasks that can be automated with AI, from deduplication and data enrichment to workflow monitoring and documentation. You will see how AI shifts CRM administration from manual maintenance to intelligent system design, and how Anablock helps make that transition practical and safe.

Unlock the Full Power of AI-Driven Transformation

Schedule Demo

See how Anablock can automate and scale your business with AI.

Book Demo

Start a Support Agent

Talk directly with our AI experts and get real-time guidance.

Call Now

Send us a Message

Summarize this page content with AI