Loading...
New Winner – Cross-Border Excellence | Payoneer India 2026 Check out
Featured Recognized by Salesforce; Proven by impact! Check out

Support agents spend a lot of time writing the same kind of customer emails, whether it is a case update, resolution message, or simple follow-up after an issue.

An email generator for Salesforce can help reduce this repetitive work by creating a first draft directly from the Case record, using the information already available in Salesforce.

With Salesforce API integration, Apex, Lightning Web Components, and Salesforce Models API, we can build a solution that creates contextual email drafts for support agents. In this step-by-step guide, we will build and configure the complete solution.

Solution Overview

The solution uses Apex, Salesforce Models API, and a Lightning Web Component to generate and manage customer-support emails from a Case record. 

Apex Class:

ModelApi.cls

  • Integrates with the Salesforce Models API.
  • Sends prompts containing Case information to the AI model (sfdc_ai__DefaultOpenAIGPT40mniMini).
  • Receives AI-generated email content from the model.
  • Handles API exceptions and returns generated responses.

EmailGenerationController.cls

  • Retrieves Case details, Contact information, status, subject, priority, product details, reason and engineering request information.
  • Dynamically builds AI prompts using Case data.
  • Generates professional customer-support email drafts through the Salesforce Models API.
  • Supports email regeneration based on additional user instructions.
  • Returns structured email data (To, CC, Subject, and Body) to the Lightning Web Component.
  • Sends finalized emails using Salesforce Email Services (Messaging.SingleEmailMessage).

Lightning Web Component:

  • Automatically generates an AI-powered email draft when the component loads.
  • Displays recipient details, subject, and generated email content in an editable interface.
  • Allows users to provide additional instructions for regenerating email content.
  • Enables modification of the generated email before sending.
  • Displays loading indicators during AI generation and regeneration requests.
  • Sends the finalized email directly from the Salesforce UI.
  • Provides success and error notifications using Salesforce toast messages.

Architecture Diagram

Architecture Diagram

What the Email Generator Can Do

Once implemented, the component can provide the following functionality:

  • AI-powered customer support email generation using Salesforce Models API.
  • Context-aware email creation based on Case information.
  • Dynamic email regeneration with custom instructions.
  • Editable rich-text email composer.
  • Automatic recipient and subject population from Case records.
  • Professional email formatting with predefined company signature.
  • Direct email sending from Salesforce.
  • Seamless integration with Lightning Experience.

Salesforce Models API

  • Uses Large Language Models (LLMs) available within Salesforce.
  • Generates intelligent, context-aware customer support emails based on Case data.
  • Creates personalized email drafts and supports regeneration with additional instructions.
  • Returns AI-generated email content for review, editing, and sending within Salesforce.

How Prompt Engineering Works

The Apex controller dynamically builds prompts using:

  • Case Subject
  • Priority
  • Product
  • Description
  • Status
  • Engineering Request Details

Example Prompt:

How Prompt Engineering Works

Prerequisites

Before implementing this solution, ensure:

Salesforce Requirements

  • Enterprise, Unlimited, or Developer Org
  • Einstein Generative AI enabled
  • AI Platform permissions assigned
  • Access to Salesforce Models API

{Setup -> Einstein Setup -> Turn on Einstein}

Required Permissions

Assign users:

  • AI Platform User
  • Prompt Builder User
  • Einstein Generative AI User

Note:

Permission availability depends on your Salesforce edition and enabled AI features.

Step-by-Step Implementation

Below are the steps to create the Case email generation solution, configure the Apex logic, build the Lightning Web Component, and add it to the Salesforce Case page.

Step 1: Create the Apex Controller

Create an Apex controller that fetches Case information and sends prompts to the Models API.

Step 1 6

Step 1.1

Step 1.2

Step 1.3

Step 1.4

Step 1.5

Step 2: Build the Lightning Web Component

Create an LWC that allows users to generate AI-powered emails directly from a Case record.

CaseEmailGenerator.html

Step 2 6

Step 2.1

Step 2.2

CaseEmailGenerator.js

Step 2.3

Step 2.4

Step 2.5

Step 2.6

Step 2.7 1

CaseEmailGenerator.css

Step 2.8

CaseEmailGenerator 01

CaseEmailGenerator 02

CaseEmailGenerator css 03

CaseEmailGenerator 03

CaseEmailGenerator 04

CaseEmailGenerator 05

CaseEmailGenerator.js-meta.xml 

CaseEmailGenerator js 01

Step 3: Add Component to Lightning Record Page

  1. Open a Case Record.
  2. Click Setup → Edit Page.
  3. Open Lightning App Builder.
  4. Drag caseEmailGenerator onto the page.
  5. Save and Activate the page.

The component is now available directly on Case records.

OUTPUT :

OUTPUT 01

OUTPUT 02

OUTPUT 03

OUTPUT 04

OUTPUT 05

Watch Demo Video

 

Conclusion

Salesforce Generative AI makes it possible to bring intelligent automation directly into everyday CRM workflows. By combining Salesforce Models API, Apex, and Lightning Web Components, support teams can reduce repetitive email-writing work while keeping everything within Salesforce.

An AI email generator can use Case information to create relevant email drafts, which agents can review, edit, regenerate, and send based on the situation. Salesforce API integration also makes this solution easier to connect with existing Salesforce processes and workflows.

The same approach can be extended to other support activities, such as:

  • AI-generated Case summaries
  • Knowledge article suggestions
  • AI-powered chat assistants
  • Automated follow-up task creation
  • Customer response recommendations

As Salesforce AI capabilities continue to evolve, developers can build smarter, faster, and more personalized customer experiences directly inside Salesforce.

Frequently Asked Questions
How can AI-generated Salesforce emails maintain a consistent brand voice?

A consistent brand voice comes from defined tone, terminology, formatting, and review guidelines. HIC Global Solutions can further customize Salesforce AI email workflows around organizational communication standards.

How should Salesforce teams review AI-generated customer emails before sending them?

Agents should verify customer details, accuracy, tone, and context before sending. HIC Global Solutions recommends keeping human review within the workflow to catch inappropriate or incomplete responses.

Can Salesforce AI email generation support different customer communication tones?

Yes, prompts can specify tones such as professional, empathetic, concise, or friendly. HIC Global Solutions can customize these instructions according to customer-service scenarios and organizational communication policies.

How can Salesforce teams scale AI-generated email workflows across support operations?

Standardized prompts, reusable components, governance, and monitoring help teams scale AI email workflows. HIC Global Solutions can extend Salesforce implementations as support volumes and requirements evolve.

Can Salesforce AI-generated emails support multilingual customer communication?

Multilingual responses can be incorporated through appropriate instructions and model capabilities. HIC Global Solutions can help design Salesforce AI workflows that accommodate language requirements while preserving intended context and tone.

Related Articles
Building a Multi-Stage Quote Approval Workflow in Salesforce

When a Quote needs approval before it can be finalized, businesses may need one or more people to review it. In Salesforce, this process can be managed through an Approval Process, which helps ensure that each Quote reaches the right approver. In this implementation, the goal was to create a dynamic, multi-stage approval process forSalesforce […]

Read More
SAP BTP to Salesforce REST API Integration: A Step-by-Step Guide

Connecting SAP applications with Salesforce can help businesses keep customer information and business processes aligned across both platforms. SAP Business Technology Platform (SAP BTP) provides an integration layer for exchanging data between these systems without building a separate connection for every application. In this example, SAP Integration Suite acts as middleware and sends JSON data […]

Read More
How to Automate Lead Qualification in GoHighLevel Using the Gemini API

GoHighLevel workflows can capture lead details and trigger webhooks, but evaluating each prospect against service fit, budget, and purchase readiness requires additional logic. Connecting an AI model makes this evaluation part of the automated process. With Gemini, submitted lead information can be assessed against predefined scoring criteria to generate a qualification status, score, reason, and […]

Read More
How to Connect Claude with Notion Using a Custom Connector

Claude becomes more useful when it can access information stored in external platforms such as Notion. This connection helps users retrieve relevant business documents without manually uploading them into Claude. A custom connector built with the Model Context Protocol (MCP) allows Claude to communicate with Notion through a dedicated server. It can search pages and […]

Read More
How to Configure Volume and Attribute-Based Discounts Using Pricing Procedures in Revenue Cloud Advanced

Revenue Cloud helps businesses automate product pricing and manage discounts according to their sales requirements. Salesforce Revenue Cloud supports structured pricing calculations, allowing organizations to apply pricing rules consistently across supported sales transactions. Revenue Cloud Advanced (RCA) provides pricing capabilities that help businesses manage product prices, volume discounts, and attribute-based adjustments. Pricing procedures bring these […]

Read More
How to Connect Salesforce with Claude AI Using an MCP Server

Claude AI can make working with Salesforce CRM data much easier. Instead of manually opening records, building reports, or writing SOQL queries, teams can ask Claude questions in plain English and get answers from their Salesforce org. With Salesforce MCP, users can explore CRM information through a conversational interface, helping them find relevant details with […]

Read More
Our Location worldwide
Indian Flag India
7th Floor, A-10, Pegasus Tower, Sector 68, Noida, Uttar Pradesh 201301 +91-1203669505
United States of America Flag USA
333 West Brown Deer Road Unit G – 366 Milwaukee WI, USA 53217 +1(262) 310-7818
United Kingdom Flag UK
7 Bell Yard, London, WC2A 2JR +44 20 3239 9428
CA Flag Canada
HIC Global Solutions INC
6D - 7398 Yonge St #1124 Thornhill, ON L4J 8J2 Canada +1(262) 310-7818