Skip to main content
Build the future with Agentforce at TDX in San Francisco or on Salesforce+ on March 5–6. Register now.

Create and Ground Prompt Templates

Learning Objectives

After completing this unit, you’ll be able to:

  • Describe what grounding is.
  • Use Prompt Builder to create a sales email prompt template.
  • Add resources to a prompt template.
  • Use an Apex class to provide data to a prompt template.

The Why and the How

In the Prompt Builder: Quick Look module, Linda Rosenberg, a Salesforce admin, aimed to reduce her sales team's manual workload by automating tasks with prompt templates. In this module, we take a deeper dive and show you why and how she did it.

Build a Sales Email Prompt Template

Note

To create a sales email prompt template in Prompt Builder, you need the Einstein for Sales, Einstein for Platform, or Einstein for Service add-on.

Linda needs to create a template that her sales team can use to generate emails. She wants to reduce the time that the team spends on creating invitations to customers for product events.

To do this, Linda navigates to Prompt Builder in Salesforce Setup. When she navigates to Prompt Builder, the first page that’s shown is the Prompt Builder Explore page. Here you’ll find:

  • Guidance to help you learn more about the features of Prompt Builder.
  • Access to prompt template walkthroughs and examples.
  • A listing of all existing prompt templates with their type, category and status.
  • Functionality to edit and delete existing prompt templates.

Prompt Builder Explore page.

From the Explore page, Linda can also create a prompt template. She clicks the New Prompt Template button.

Template type setup.

Linda starts to complete the fields in the template type setup screen.

When you set up a prompt template, it’s important to have a clear goal. In this case, Linda must think about who her company’s customers are and what the sales team wants them to see in the email.

Linda understands that her email may be sent to any Cloud Kicks contact. Therefore, Contact is the recipient object. She completes the template type setup by selecting:

  1. Prompt Template Type: Sales Email
  2. Prompt Template Name: Invite Customer to Local Product Event
  3. API Name: Invite_Customer_to_Local_Product_Event
  4. Template Description: Email customer to invite to local product event.
  5. Recipient: Contact
  6. Related Object: Account

Ground Your Template

You learned that making templates specific makes them effective. Another way of saying “specific” is to say your template is grounded.

Once Linda has defined her template type, she begins drafting and grounding her prompt in the Template Workspace.

Prompt template workspace with prompt.

Linda includes the customer name, who the email is from, their titles, and details about the event.

You are a Salesforce admin and your name is Linda Rosenberg from the organization Cloud Kicks. Your prospect is Rob Hutchinson, a director from Acme Inc., and they are based in Toronto, Ontario.

In the email, invite the prospect to attend the event “Floating on Clouds: Toronto Kickoff” on September 18, an event for customers of Cloud Kicks new and old to network and preview upcoming products, in no more than 70 words. Explain to the prospect the possible benefits of attending the event and mention that you would be happy to chat with them further at the event or online if they need more information.

The prompt looks great. However, her first draft is hard-coded for only one specific sender and recipient. That would be okay if the prompt is going to be used once. But the concept of a prompt template is that it can be used for any sender and recipient. What she needs is a way to get her company’s CRM data into the template and ground it automatically.

Happily, Linda knows that she can use merge fields, Apex, and Flow as resources to enable Prompt Builder to securely access Salesforce data.

Add Merge Fields to a Prompt Template

Linda reviews her prompt and looks for areas where she can use merge fields to take her prompt from hardcoded for one-time use to reusable for any sender and recipient.

You are a Salesforce admin and your name is Linda Rosenberg from the organization Cloud Kicks. Your prospect is Rob Hutchinson, a director. They are based in Toronto, Ontario.

In the email, invite the prospect to attend the event “Floating on Clouds: Toronto Kickoff” on September 18, an event for customers of Cloud Kicks new and old to network and preview upcoming products, in no more than 70 words. Explain to the prospect the possible benefits of attending the event and mention that you would be happy to chat with them further at the event or online if they need more information.

Within the Prompt Template Workspace, Linda uses the Resource picklist to choose the type of resource to use. She sees there are multiple options for sales email prompt templates. Current Organization, Sender, and Recipient are all available to use in her prompt template.

List of resources including Current Organization, Sender, and Recipient.

In the Resources picklist, Linda selects Sender and Recipient, where she then selects specific information, like title, name, company, and so on to ground her prompt template. She saves her work.

Resource picker displays the sender merge fields available.

Resource picker displays the recipient merge fields available.

Note

In this module you’ll see the syntax {!$Resource} in the prompt templates. This special syntax helps you to easily copy and paste the text from this module into the Prompt Template Workspace. It ensures all of your resources stay where and how you expected them in your template.

You are a {!$Input:Sender.Title} and your name is {!$Input:Sender.Name} from {!$Input:Sender.CompanyName}. Your prospect is {!$Input:Recipient.Name}, a {!$Input:Recipient.Title}. They are based in {!$Input:Recipient.MailingCity}.

In the email, invite the prospect to attend the event "Floating on Clouds: Toronto Kickoff" on September 18, an event for customers of Cloud Kicks new and old to network and preview upcoming products, in no more than 70 words. Explain to the prospect the possible benefits of attending the event and mention that you would be happy to chat with them further at the event or online if they need more information.

After she’s done, she notices there’s one piece of her prompt that needs an adjustment before it can display the correct response: "Floating on Clouds: Toronto Kickoff" on September 18.

At Cloud Kicks, “Floating on Clouds” is a nationwide event that hosts local customers based on their city. Linda wants to make sure the sales email prompt template is as personalized as possible and generates emails that invite customers to local events.

Linda understands that using only merge fields for this portion isn't enough. She needs logic incorporated into her prompt template. There are several approaches to accomplish this within Prompt Builder, including using Apex or Template-Triggered Prompt Flows. First, let’s explore how to use Apex in prompt templates.

Add Apex to a Prompt Template

If you want to use data from a SOQL query or an external API in your prompt, consider Apex. Apex is also effective if you want to generate well-formatted JSON or do programmatic data filtering.

In this case, Linda wants to create an Apex class that finds events that are close to a given contact and returns the name of the event, subject, location, and start time. Using the Developer Console she creates a class named ContactEventsPrompt with a method annotated as InvocableMethod. The InvocableMethod must accept List<Request> where the inputs defined in the Request class match the inputs within the prompt. Also, the InvocableMethod must be labeled with the CapabilityType that matches the template type.

Note

If you are interested in learning more about adding Apex classes to prompt templates or to see code samples, check out the Salesforce Documentation.

Once her class is created, Linda returns to the Prompt Template Workspace in Prompt Builder and notices that Apex is now a resource. She adds the Apex class by clicking Resource and selecting Apex.

List of resources including Apex, Current Organization, Sender, and Recipient.

Resource picker displays the Apex class available.

You’re a {!$Input:Sender.Title} and your name is {!$Input:Sender.Name} from {!$Input:Sender.CompanyName}. Your prospect is {!$Input:Recipient.Name}, a {!$Input:Recipient.Title}. They are based in {!$Input:Recipient.MailingCity}.

In the email, invite the prospect to attend an event for customers of Cloud Kicks new and old to network and preview upcoming products, in no more than 70 words.Explain to the prospect the possible benefits of attending the event and mention that you would be happy to chat with them further at the event or online if they need more information.

Add the following event information to the email: {!$Apex:ContactEventsPrompt.Prompt}.

Great! Now instead of referencing one single event. Linda can rely on her Apex class to return an event close to the specified contact.

Resources

Share your Trailhead feedback over on Salesforce Help.

We'd love to hear about your experience with Trailhead - you can now access the new feedback form anytime from the Salesforce Help site.

Learn More Continue to Share Feedback