Contact Us

June 11, 2024

June 17, 2026 10:43 pm

Enhancing Prompt Builder with Case Emails and Knowledge Articles in Agentforce

Share with

Understanding the Limitation

When working with Prompt Builder, the primary object is used to determine the available fields in the prompt. In this case, the primary object is Case, and the EmailMessage fields are related to the Case object but are not directly available in the prompt.

The root cause of this issue is the way the Prompt Builder handles related objects and fields. The EmailMessage fields are not included in the prompt by default, and there is no direct way to access them.

Including Case Emails in the Prompt

To include the last 5 emails in the prompt, you can use Flow or Apex to summarize and store the emails on the Case object. This approach allows you to create a custom field on the Case object that contains the summary of the emails.

Apex Example

// Example Apex code to summarize emails and store on Case object
List<Case> cases = [SELECT Id, Subject FROM Case];
for (Case c : cases) {
    List<EmailMessage> emails = [SELECT Subject, Body FROM EmailMessage WHERE ParentId = :c.Id ORDER BY CreatedDate DESC LIMIT 5];
    String emailSummary = '';
    for (EmailMessage email : emails) {
        emailSummary += email.Subject + ' - ' + email.Body + '
';
    }
    c.Email_Summary__c = emailSummary;
    update c;
}

Alternatively, you can use a custom component to fetch the emails and display them in the prompt.

Knowledge Article Integration

Prompt Builder can automatically use Knowledge Articles via grounding, but it is recommended to explicitly pass Knowledge summaries into the prompt for better control and customization.

Heads up: When using Knowledge Articles in prompts, make sure to configure the Knowledge settings correctly to avoid any issues.

Best Practices

Checklist for Using Case Emails and Knowledge Articles in Prompt Builder

  • Use Flow or Apex to summarize and store emails on the Case object
  • Use a custom component to fetch emails and display them in the prompt
  • Explicitly pass Knowledge summaries into the prompt for better control and customization
  • Configure Knowledge settings correctly to avoid any issues
  • Test and validate the prompt to ensure it is working as expected

Frequently Asked Questions

What is the recommended approach for including Case Emails in the prompt?

Using Flow or Apex to summarize and store emails on the Case object is a recommended approach.

Can Prompt Builder automatically use Knowledge Articles via grounding?

Yes, Prompt Builder can automatically use Knowledge Articles via grounding, but it is recommended to explicitly pass Knowledge summaries into the prompt for better control and customization.

What are the benefits of using a custom component to fetch emails and display them in the prompt?

Using a custom component allows for better control and customization of the email display, and can also improve performance by reducing the number of API calls.

How do I configure Knowledge settings correctly to avoid any issues?

To configure Knowledge settings correctly, make sure to follow the documentation and best practices provided by Salesforce, and test and validate the Knowledge settings to ensure they are working as expected.

Genetrix Technology · Salesforce Marketing Cloud Partner

Need help shipping this in production?

Genetrix builds and untangles Salesforce Marketing Cloud and Agentforce setups for teams that want it done right the first time. If anything in this post sounds familiar, talk to us before it ships.

Get in Touch with Genetrix →

Blogs for the

Business-Savvy!​

Let’s Connect

A 30 min no cost strategy session
with cloud support expert

Let’s Connect

A 30 min no cost strategy session
with cloud support expert