Prompt Engineering consists of 30% of total score in Salesforce Agentforce Specialist Exam. The topic covers prompt components, prompt templates, and prompt builder.
NOTE
Most of the content in this work was generated with the assistance of AI and carefully reviewed, edited, and curated by the author. If you have found any issues with the content on this page, please do not hesitate to contact me at support@issacc.com.
π§ Prompt Engineering & Einstein Prompt Builder
π‘ Use Prompt Builder to create, test, and integrate reusable AI prompt templates in Salesforce.
π― Learning Objectives
After studying this topic, you should be able to:
- β Describe how to use Prompt Builder to create prompt templates for AI-generated responses.
- β Identify the types of prompt templates.
- β Explain how to use prompt templates in flows and automations.
- β Match business requirements to the correct Prompt Builder solution.
βοΈ Overview: What is Prompt Builder?
Prompt Builder is a Salesforce tool that lets you:
- Create detailed reusable prompt templates for LLM-generated responses.
- Use ingredients, guidelines, and grounding to guide the model.
- Test and refine templates in a Prompt Template Workspace.
- Integrate them into flows, REST APIs, or Apex for automation.
π§© Reusable Template Types
Category | Description |
---|---|
π¬ Sales Email | Generates personalized customer emails. |
π§Ύ Field Generation | Populates dynamic form fields. |
π Record Summary | Summarizes record data. |
π§ Flex | Custom prompts for any business use case. |
πββοΈ Contextual Service Replies | Adapts live chat replies using session data. |
π Grounded Service Replies | Uses knowledge or case histories. |
π‘ Knowledge Answers | Customizes tone and content of answers. |
π§± Prompt Components
βοΈ Prompt
Detailed instructions sent to an LLM to produce a response.
π§© Prompt Template
Reusable structure built in Prompt Builder that defines:
- Context
- Data grounding
- Style & tone guidelines
βοΈ Prompt Ingredients
- Participants β whoβs involved
- Setting β scenario or context
- Goal β desired output
- Relationships β between entities
- Data β key input sources
π§ Prompt Guidelines
Define limits, tone, style, and language.
π Grounding
Connects prompts to real Salesforce or external data to add accuracy and context.
π§° Using Prompt Builder
π Enablement
- Enable Einstein Generative AI.
- Assign appropriate permission sets:
- π§βπ»
Prompt Template Manager
β create/manage templates. - π€
Prompt Template User
β access/run templates. - βοΈ
Einstein Sales Emails
β draft sales emails.
- π§βπ»
πͺ Navigation
Setup β Prompt Builder β New Prompt Template
ποΈ Creating Prompt Templates
π§± Steps
- Choose a Prompt Template Type (e.g., Field Generation, Sales Email).
- Provide Name & Description.
- Configure object, field, or resources.
- Draft and ground prompts in Prompt Template Workspace.
- Test with Preview (shows resolution & response).
- Select LLM configuration (e.g., GPT-4 Turbo, BYO-LLM).
- Save, Activate, and assign to flows or users.
π§ͺ Prompt Template Workspace
Section | Function |
---|---|
βοΈ Drafting Area | Write and format prompt with merge fields. |
π Resources Panel | Select record fields, flows, Apex, DMOs, etc. |
π Preview | Test resolved prompt (Resolution + LLM Response). |
βοΈ Configuration Panel | Choose LLM and test inputs (for Flex). |
π§© Prompt Template Types (Detailed)
Type | Purpose | Example |
---|---|---|
π¬ Sales Email | Personalized outreach emails. | βDraft with Einsteinβ button on Leads/Contacts. |
π§Ύ Field Generation | Auto-fill form fields. | Generate summary text on a Case field. |
π Record Summary | Summarize record data. | Show case resolution summary. |
π§ Flex | Any unique case not covered by other types. | Create multi-object sales proposals. |
πββοΈ Contextual Service Replies | Chat replies using session data. | Live chat customer support. |
π Grounded Service Replies | Use knowledge articles for responses. | Knowledge-based agent chat. |
π‘ Knowledge Answers | Answer questions using knowledge base. | FAQ automation. |
πͺ Campaign Brief | Create marketing campaign outlines. | Define campaign goals and message. |
π Case Summary | Generate case summaries. | Issue + resolution summary. |
π§Ύ Contract Analysis | Extract clauses and key data from contracts. | Renewal dates, pricing, conditions. |
π Generate Case Description / Subject | Create support case content. | βBilling issue with subscriptionβ |
π£ Sales Pitch Coaching | Analyze transcripts for feedback. | Improve objection handling. |
π Security Risk Analysis | Recommend mitigations. | MFA enforcement suggestion. |
π Record Prioritization | Rank records based on metrics. | Identify top opportunities. |
π§° Work Summary | Summarize post-interaction logs. | Wrap-up case details. |
π Integrating Prompt Templates
π§ How Theyβre Used
Use Case | Execution Method |
---|---|
βοΈ Sales Email | βDraft with Einsteinβ button. |
π§Ύ Field Generation | Click the AI icon beside form field. |
βοΈ Flex Template | Invocable Action / REST API / Apex Connect. |
π In Flows
- Template-Triggered Prompt Flow:
Provides data and adds logic to templates. - Prompt Template Flow Action:
Invokes a specific prompt template and returns response.
π Example: Retrieve related Cases via Flow and feed them into a Record Summary template.
π₯ User Roles & Permissions
Role | Permission Set | Capabilities |
---|---|---|
π€ Prompt Template User | Prompt Template User | Run templates, see AI field icons. |
π§βπ» Prompt Template Manager | Prompt Template Manager | Create & manage templates in Setup. |
βοΈ Sales Email User | Einstein Sales Emails | Draft AI emails for Leads/Contacts. |
β οΈ Ensure users have field-level access; missing fields result in placeholder values.
π§© Creating, Activating, and Executing
π§± Create
- Select Type β Name β Description
- Define Resources & Merge Fields
- Draft prompt with clear context and instructions (inside
""" triple quotes """
)
π§ͺ Test & Preview
- Select sample records
- View Resolution (full resolved text)
- Review Response (AI output)
π Activate
- Click Activate β makes template immutable
- Only one active version at a time
π Versioning
- Save as New Version β same template
- Save as New Template β copy variant
- Standard templates β can only Save As New Template
π§ Best Practices
π§© Good prompts = Clear + Contextual + Grounded
Principle | Description |
---|---|
βοΈ Clarity & Brevity | Write concise, natural-language instructions. |
π¬ Consistency | Maintain tone, word choice, and structure. |
π Context / Roleplay | Give LLM a persona (e.g., βYou are a sales repβ¦β). |
π§± Triple-Quoted Instructions | Separate context from commands using """ . |
π Iterate & Test | Compare multiple responses for consistency. |
β οΈ Direct Instructions | Tell LLM exactly what to produce (not how). |
π« Limitations
- β User/Organization related lists not supported as merge fields.
- β Activities related list unsupported on Account & Case.
- βοΈ Max 5 related list merge fields per template.
- β‘ Requires Dynamic Forms for field generation templates.
- β οΈ Token count varies per record; may cause intermittent errors.
- π Grounding data must be accurate & complete to avoid missing info.
πͺ Grounding Techniques
Grounding connects templates to Salesforce data, external APIs, or unstructured text.
Technique | Description | Example |
---|---|---|
π Record Merge Field | Link to object field (Input:Account.Name ). | Use lead name in email. |
π Related List Merge Field | Pull related list in JSON (Related List: Account.Contacts ). | Include related contacts. |
π Flow Merge Field | Trigger Flow logic (Flow:Get_Opportunities_Flow ). | Fetch dynamic data. |
βοΈ Apex Merge Field | Call Apex class (Apex:ContactEventsPrompt ). | Return external API data. |
βοΈ DMO Merge Field | Use Data Cloud objects. | Enrich Salesforce record. |
π§© Record Snapshot | Use fields visible on record page. | Current Account view. |
π RAG (Retrieval Augmented Generation) | Add unstructured data context (knowledge, chat logs). | Search docs via Einstein Retriever. |
π§ Combine grounding sources for hybrid context.
π§ͺ Scenario Examples
Business Case | Recommended Solution |
---|---|
βοΈ ABC Lights β Send personalized product emails. | Sales Email template grounded in product preferences. |
π§Ύ ABC Hotels β Summarize guest interests. | Field Generation template for Contact page. |
π ABC Hardware β Generate order summaries. | Flow + Prompt Template action displaying AI summary. |
πͺ ABC Computers β Draft proposals from multiple objects. | Flex template referencing multiple objects. |
π§ ABC Electronics β Standardize AI prompts. | Reusable Prompt Templates in workflows. |
π ABC Furniture β AI description with human oversight. | Field Generation template + editable dynamic form. |
π ABC Furniture (API) β Use external REST API. | Flow + Add Prompt Instructions + Flow merge field grounding. |
π§© Grounding in Action (Use Cases)
Scenario | Grounding Technique |
---|---|
Use up-to-date lead info for follow-ups. | Record Merge Fields |
Retrieve recent opportunities for summary. | Flow Merge Field |
Bring Data Cloud insights. | Template-Triggered Prompt Flow |
Include external REST API data. | Flow Merge Field / Apex |
Integrate unstructured data (articles, chats). | Retrieval Augmented Generation |
π§± Model Configuration
- Default: OpenAI GPT-4 Turbo
- Custom: via Einstein Studio β Model Playground
- Configure hyperparameters, LLM selection, or BYO-LLM (Bring Your Own).
π Key Takeaways
π Prompt Builder turns prompt engineering into a scalable Salesforce capability.
- Build reusable, grounded, high-quality prompt templates.
- Manage lifecycle: Create β Test β Activate β Integrate.
- Ensure user permissions, data grounding, and best practices for accuracy.
- Use flows and invocable actions to integrate seamlessly with business processes.
- Follow clarity, consistency, and grounding to achieve reliable AI outcomes.
π Flow Charts
1) Prompt Builder Lifecycle
flowchart TD A[Start Business Requirement] --> B[Choose Template Type] B --> C[Open Prompt Builder in Setup] C --> D[Draft Prompt: context, instructions, tone] D --> E[Add Grounding: record, flow, apex, DMO, snapshot, RAG] E --> F[Select Model Configuration] F --> G[Save Template] G --> H{Preview Records?} H -- No --> I[Select Records and Test Inputs] I --> J[Preview Resolution and Response] H -- Yes --> J J --> K{Meets Quality?} K -- No --> D K -- Yes --> L[Activate Template] L --> M{Execution Type} M --> M1[Sales Email via Draft with Einstein] M --> M2[Field Generation via AI Icon] M --> M3[Flex via Flow or API] M --> M4[Service Replies or Knowledge] L --> N[Versioning Save As New Version or Template] N --> D
2) Template Type Selector
flowchart LR R[Requirement] -->|Email to customer| SE[Sales Email] R -->|Populate field| FG[Field Generation] R -->|Summarize record| RS[Record Summary] R -->|Chat response| CSR[Contextual Service Replies] R -->|Knowledge based reply| GSR[Grounded Service Replies] R -->|Knowledge answer| KA[Knowledge Answers] R -->|Custom or multi object| FLEX[Flex] R -->|Marketing brief| CB[Campaign Brief] R -->|Case summary| CS[Case Summary] R -->|Contract review| CA[Contract Analysis] R -->|Case subject or description| GCS[Generate Case Info] R -->|Sales coaching| SPC[Sales Pitch Coaching] R -->|Security risk analysis| SRA[Security Risk] R -->|Record ranking| RP[Record Prioritization] R -->|Work summary| WS[Work Summary]
3) Grounding Techniques
flowchart TD A[Need Data for Prompt] --> B{Choose Source} B -->|Single Object| C[Record Merge Field] B -->|Related List| D[Related List Merge Field] B -->|Flow Logic| E[Flow Merge Field] B -->|Apex Logic| F[Apex Merge Field] B -->|Data Cloud| G[DMO Merge Field] B -->|Snapshot| H[Record Snapshot] B -->|Unstructured Data| I[RAG Retriever] E --> J[Add Prompt Instructions] I --> K[Attach Retriever in Einstein Studio]
4) Template-Triggered Flow
flowchart LR UA[User Runs Template] --> T[Prompt Template with Flow Merge Field] T --> F[Template Triggered Flow] F --> F1[Get Records and Data Cloud Data] F --> F2[Optional External API Call] F --> F3[Add Prompt Instructions] F --> T2[Template Resolution] T2 --> LLM[Selected LLM] LLM --> OUT[Response to User]
5) Execution by Template Type
flowchart TD A[Activated Template] --> B{Type} B -->|Sales Email| C[Draft with Einstein] B -->|Field Generation| D[Click AI Field Icon] B -->|Flex| E[Invoke Flow or REST] B -->|Service Replies| F[Live Chat] B -->|Knowledge Answers| G[Agent Knowledge] B -->|Record Summary| H[Summarize Record Action]
6) Permissions Overview
flowchart LR A[Enable Einstein Gen AI] --> B[Assign Permissions] B --> B1[Prompt Template Manager] B --> B2[Prompt Template User] B --> B3[Einstein Sales Emails] C[Use Field Generation] --> D{Dynamic Forms?} D -- No --> E[Upgrade to Dynamic Forms] D -- Yes --> F[Show AI Field Icon] G[Sales Email User] --> H{Has Field Access?} H -- No --> I[Grant Access] H -- Yes --> J[Ready to Use]
7) Versioning and Governance
flowchart TD A[Edit Template] --> B{Standard or Custom} B -- Standard --> C[Save as New Template] B -- Custom --> D[Save as New Version or Template] D --> E[Activate Version] C --> E E --> F[Collect Feedback] F --> G{Need Changes?} G -- Yes --> A G -- No --> H[Publish and Train Users]
8) Prompt Design Loop
flowchart LR R[Define Requirement] --> P[Write Prompt with Context and Instructions] P --> G[Add Grounding Data] G --> T[Test on Sample Records] T --> Q{Quality Check} Q -- Fail --> P Q -- Pass --> A[Activate and Execute]
π Flashcards
What is Prompt Builder?
A Salesforce tool that lets users create, test, and manage reusable prompt templates for large language models (LLMs).
Templates guide AI responses using ingredients, guidelines, and grounding data from Salesforce records.
What is a Prompt Template?
A reusable detailed prompt that includes context, instructions, tone, and grounding sources.
It can be integrated into workflows, flows, and invocable actions for consistent AI-generated results.
What are the core parts of a Prompt?
Ingredients: participants, setting, goal, relationships, data
Guidelines: tone, style, language, limits
Grounding: real Salesforce or external data
Instructions: specific commands for the LLM
What are the main Prompt Template Types?
Type Purpose Sales Email Generate personalized emails Field Generation Populate record form fields Record Summary Summarize record data Flex Custom use cases or multi-object Contextual Service Replies Real-time chat replies Grounded Service Replies Replies grounded in articles or cases Knowledge Answers Use knowledge base for responses
What is the Prompt Template Workspace used for?
A dedicated area to draft, ground, and test prompt templates.
Includes:
Drafting section
Resource picker for grounding
Preview section (resolution and response)
Configuration panel to choose LLM model
How can you use a Prompt Template in Salesforce?
Sales Email: via βDraft with Einsteinβ button
Field Generation: via AI icon beside a form field
Flex: via Flow, REST API, or Apex
Service Replies: in Live Chat or Messaging
Record Summary: via standard invocable action
What are the user roles and permission sets needed?
Role Permission Set Purpose Prompt Template Manager Create and manage templates Prompt Template User Run templates, see AI field icon Einstein Sales Emails Draft emails with AI Field-level access is required for all involved records.
What are some best practices when creating prompt templates?
Be clear, concise, and consistent
Include roleplay context (for example, βYou are a sales repβ¦β)
Place instructions inside triple quotes (
"""
)Iterate and test multiple responses
Include direct instructions (βGenerate only the summaryβ)
What are key limitations to remember?
User and Organization related lists not supported
Activities related list unsupported on Account and Case
Maximum of 5 related list merge fields
Field Generation requires Dynamic Forms
Token limits vary by record
Grounding data must be accurate for expected results
What are the main Grounding Techniques?
Technique Description Record Merge Field Link to Salesforce object field Related List Merge Field Include child records Flow Merge Field Bring data via Flow Apex Merge Field Use Apex class for data logic DMO Merge Field Use Data Cloud unified objects Record Snapshot Use current record view RAG Retriever Add context from unstructured data
What is a Template-Triggered Prompt Flow?
A Flow designed to add data or logic to a prompt template before execution.
Uses Add Prompt Instructions element
Returns enriched data through flow merge fields
Useful for complex cases like external APIs or Data Cloud data
How do you create and activate a Prompt Template?
Go to Setup β Prompt Builder β New Prompt Template
Choose template type, name, description
Add grounding fields or flows
Test with sample records
Click Activate to make it available
Only one active version per template
What are some example business scenarios?
Cosmic Lights: personalized product emails β Sales Email template
Cosmic Hotels: guest summary field β Field Generation template
Cosmic Hardware: sales order summary β Flow + Prompt Template action
Cosmic Electronics: reusable prompt library β Prompt Builder templates
Cosmic Furniture: REST API + Flow β Template-Triggered Prompt Flow
What happens when editing a Prompt Template?
You can Save as New Version or Save as New Template
Standard templates can only be saved as new custom templates
Must be activated to make usable
Only one version active at a time
What are the main quality checks for prompt templates?
Responses should be:
- Factually accurate
- Safe and unbiased
- Clear and complete
- Consistent across multiple test records
What are the best model configuration options?
Use standard GPT-4 Turbo configuration
Or create a custom one in Einstein Studio (Model Playground)
Bring your own LLM (BYO-LLM) if needed
What is the purpose of Grounding in prompts?
To connect AI generation with real Salesforce or external data for context, accuracy, and personalization.