本文是《Prompt Builder Basics | Prompt Builder 基础》的练习操作步骤。阅读原文请见:Prompt Builder Basics | Prompt Builder 基础。
1. Prepare Your Org
- Open the Quick Start: Prompt Builder project and click Create Playground. Your new org is automatically attached to your Trailhead account.
- Make note of your org's expiration date and complete the badge before then.
- Click the gear icon and select Setup.
- In Quick Find, search for and select Einstein Setup, and ensure the Turn on Einstein toggle is On; refresh your browser.
- To create a sales email prompt template, your org needs the Einstein for Sales, Einstein for Platform, or Einstein for Service add-on. Search for and select Einstein for Sales, and turn on Sales Emails.
2. Create a Sales Email Prompt Template
- In Setup, search for and select Prompt Builder to open the Prompt Builder Explore page.
- Click New Prompt Template and set:
- Prompt Template Type: Sales Email
- Prompt Template Name:
Invite Customer to Local Product Event - API Name:
Invite_Customer_to_Local_Product_Event - Template Description:
Email customer to invite to local product event. - Recipient: Contact
- Related Object: Account
- Click Next.
3. Ground the Template with Merge Fields
- In the Prompt Template Workspace, paste the first hard-coded draft of the email prompt.
- Replace the hard-coded values with merge fields using the Resources picklist:
- "Salesforce admin" → Sender > Title
- "Linda Rosenberg" → Sender > Name
- "Cloud Kicks" → Sender > Company Name
- "Rob Hutchinson" → Recipient > Name
- "a director" → Recipient > Title
- "Toronto, Ontario" → Recipient > Mailing City
- Your prompt now reads:
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}.
- Click Save.
4. Create and Add the ContactEvents Apex Class
- Open the Developer Console (click the gear icon and select Developer Console).
- Click File → New → Apex Class.
- Enter
ContactEventsas the class name and click OK. - Replace the default template with the following code:
public with sharing class ContactEvents {
// Inputs for the prompt template — must match the inputs in the prompt.
// Sales Email requires Sender (User) and Recipient (Contact).
public class Request {
@InvocableVariable(required=true)
public User Sender;
@InvocableVariable(required=true)
public Contact Recipient;
}
// Output returned to the prompt template via {!$Apex:ContactEvents.Prompt}.
// The output field must be named "Prompt" (capital P).
public class Response {
@InvocableVariable
public String Prompt;
}
// capabilityType must match the template type (Sales Email).
@InvocableMethod(
label='Get Contact Events'
description='Returns upcoming events for the specified contact'
capabilityType='PromptTemplateType://einstein_gpt__salesEmail'
)
public static List<Response> getContactEvents(List<Request> requests) {
List<Response> responses = new List<Response>();
for (Request req : requests) {
// Query standard Event records where the contact is an invitee (WhoId).
List<Event> events = [
SELECT Subject, Description, Location, StartDateTime
FROM Event
WHERE WhoId = :req.Recipient.Id
ORDER BY StartDateTime ASC
];
// Build the prompt text with event name, description, location, and start time.
String promptText = '';
for (Event evt : events) {
promptText += 'Event Name: ' + evt.Subject + '\n';
promptText += 'Description: ' + evt.Description + '\n';
promptText += 'Location: ' + evt.Location + '\n';
promptText += 'Time: ' + evt.StartDateTime.format() + '\n-\n';
}
Response resp = new Response();
resp.Prompt = promptText;
responses.add(resp);
}
return responses;
}
}
- Click Save (Ctrl+S) and verify the class compiles without errors.
- Return to Prompt Builder and reopen the Invite Customer to Local Product Event template.
- Click Resources and select Apex > ContactEvents.
- Replace the hard-coded event line (the "Floating on Clouds: Toronto Kickoff" details) with:
Add the following event information to the email: {!$Apex:ContactEvents.Prompt}.
- Click Save.
5. Create a Field Generation Prompt Template
- Create the Case AI Summary custom field on the Case object:
- Click the gear icon and select Setup.
- Open Object Manager, search for and select Case.
- Click Fields & Relationships, then New.
- Select Text Area (Long) as the Data Type, then Next.
- Field Label:
Case AI Summary; the API Name auto-populates asCase_AI_Summary__c. - Click Next through field-level security, then Save.
- In Prompt Builder, click New Prompt Template and set:
- Prompt Template Type: Field Generation
- Prompt Template Name:
Case Comments Summary - API Name:
Case_Comments_Summary - Template Description:
Summary of case details. - Object: Case
- Object Field: Case_AI_Summary__c
- Click Next and, in the Template Workspace, enter:
You are a support representative who is tasked with creating a short summary of a case that happened between a customer and a company support rep.
- Click Save, then Activate.
6. Configure the Field in Lightning App Builder
- Open the Case record page in Lightning App Builder (click the gear icon and Edit Page).
- Drag a Record Detail component (or Field Section component) onto the page.
- For a Record Detail component, migrate it to Dynamic Forms by clicking Upgrade in the right-hand panel and following the wizard.
- Add the Case AI Summary field to the page (it must be a writable text, text area, text area (long), or text area (rich) field — read-only fields aren't supported).
- In the Einstein Generative AI section of the Field Properties panel, select Case Comments Summary as the Prompt Template.
- Click Save, then Activate.
7. Create a Template-Triggered Prompt Flow
- Open the App Launcher, enter
Flow, and select Flows, then click New Flow. - In Search Automations, enter
templateand select Template-Triggered Prompt Flow. - In the Start panel, set:
- Input Type: Automatic Inputs
- Prompt Template Type: Field Generation Template Capability
- Object: Case
- Add a Get Records element:
- Label:
Get Case Comments - Object: Case Comment
- Condition: Parent ID Equals → Prompt Template Input > Case > Case ID
- How Many Records to Store: All records
- Label:
- Add a Decision element after Get Records:
- Label:
Comments Found? - Outcome Label:
Yes; Resource: Case Comments from Get Case Comments, Operator: Is Empty, Value: False - Default Outcome Label:
No
- Label:
- On the Yes path, add a Loop element:
- Label:
Loop Comments - Collection Variable: Case Comments from Get Case Comments
- Direction: First item to last item
- Label:
- On the Yes path, add an Add Prompt Instructions element:
- Label:
Send Comments to Prompt - Prompt Instructions:
Summarize the case's comments using, then insert Current Item from Loop Loop_Comments > CommentBody.
- Label:
- On the No path, add another Add Prompt Instructions element:
- Label:
No Comments for Prompt - Prompt Instructions:
The case has no comments to summarize.
- Label:
- Save the flow as
Get Case Summary, then click Activate.
8. Add the Flow to the Prompt Template
- Return to Prompt Builder and open the Case Comments Summary template.
- Click Insert Resource and select Flows > Get Case Summary.
- The flow is inserted as
{!$Flow:Get_Case_Summary.Prompt}. Click Save.
9. Create a Flex Prompt Template
- In Prompt Builder, click New Prompt Template and set:
- Prompt Template Type: Flex
- Prompt Template Name:
Product Details - API Name:
Product_Details - Template Description:
Information about product
- Define three resources:
- Name
Account Info, API NameAccount_Info, Object Account - Name
Asset Info, API NameAsset_Info, Object Asset - Name
Contact Info, API NameContact_Info, Object Contact
- Name
- Click Next and enter:
Write a detailed product description using this information:
The Account Name is {!$Input:Account_Info.Name}
The Product Info is {!$Input:Asset_Info.Description}
The Contact Info is {!$Input:Contact_Info.Name}
- Click Save.
10. Preview and Review a Response
- Open the Invite Customer to Local Product Event sales email template.
- In the Preview Settings, select the recipient record Andy Smith (Contact) and click Save & Preview.
- Review the Resolved Prompt — the merge fields are replaced with the selected record data, and the Apex resource shows the returned event information.
- Review the Response section to confirm the LLM generated a personalized email based on the Salesforce data.
11. Add Guardrails and Save as a New Version
- With the sales email template open, click Save As and select Save as a New Version.
- Revise the prompt to add guardrails for accuracy and safety:
You must treat equally any individuals or persons from different socioeconomic statuses, sexual orientations, religions, races, physical appearances, nationalities, gender identities, disabilities, and ages. When you do not have sufficient information, you must choose the unknown option, rather than making assumptions based on any stereotypes.Follow the instructions precisely, do not add any information not provided.Summarize in 1 sentence, and use clear, concise, and straightforward language using the active voice and strictly avoiding the use of filler words and phrases and redundant language.Keep the emotion of the summary relaxed.
- Click Save and Activate. The active version is what other features use when a user drafts an email or generates a record field.
