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

CategoryDescription
πŸ’¬ Sales EmailGenerates personalized customer emails.
🧾 Field GenerationPopulates dynamic form fields.
πŸ“„ Record SummarySummarizes record data.
🧠 FlexCustom prompts for any business use case.
πŸ’β€β™€οΈ Contextual Service RepliesAdapts live chat replies using session data.
πŸ“š Grounded Service RepliesUses knowledge or case histories.
πŸ’‘ Knowledge AnswersCustomizes 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

  1. Enable Einstein Generative AI.
  2. 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

  1. Choose a Prompt Template Type (e.g., Field Generation, Sales Email).
  2. Provide Name & Description.
  3. Configure object, field, or resources.
  4. Draft and ground prompts in Prompt Template Workspace.
  5. Test with Preview (shows resolution & response).
  6. Select LLM configuration (e.g., GPT-4 Turbo, BYO-LLM).
  7. Save, Activate, and assign to flows or users.

πŸ§ͺ Prompt Template Workspace

SectionFunction
✏️ Drafting AreaWrite and format prompt with merge fields.
πŸ”— Resources PanelSelect record fields, flows, Apex, DMOs, etc.
πŸ‘ PreviewTest resolved prompt (Resolution + LLM Response).
βš™οΈ Configuration PanelChoose LLM and test inputs (for Flex).

🧩 Prompt Template Types (Detailed)

TypePurposeExample
πŸ’¬ Sales EmailPersonalized outreach emails.β€œDraft with Einstein” button on Leads/Contacts.
🧾 Field GenerationAuto-fill form fields.Generate summary text on a Case field.
πŸ“„ Record SummarySummarize record data.Show case resolution summary.
🧠 FlexAny unique case not covered by other types.Create multi-object sales proposals.
πŸ’β€β™€οΈ Contextual Service RepliesChat replies using session data.Live chat customer support.
πŸ“š Grounded Service RepliesUse knowledge articles for responses.Knowledge-based agent chat.
πŸ’‘ Knowledge AnswersAnswer questions using knowledge base.FAQ automation.
πŸͺ„ Campaign BriefCreate marketing campaign outlines.Define campaign goals and message.
πŸ“‘ Case SummaryGenerate case summaries.Issue + resolution summary.
🧾 Contract AnalysisExtract clauses and key data from contracts.Renewal dates, pricing, conditions.
🎟 Generate Case Description / SubjectCreate support case content.”Billing issue with subscription”
πŸ—£ Sales Pitch CoachingAnalyze transcripts for feedback.Improve objection handling.
πŸ” Security Risk AnalysisRecommend mitigations.MFA enforcement suggestion.
πŸ“Š Record PrioritizationRank records based on metrics.Identify top opportunities.
🧰 Work SummarySummarize post-interaction logs.Wrap-up case details.

πŸ” Integrating Prompt Templates

🧠 How They’re Used

Use CaseExecution Method
βœ‰οΈ Sales Emailβ€œDraft with Einstein” button.
🧾 Field GenerationClick the AI icon beside form field.
βš™οΈ Flex TemplateInvocable 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

RolePermission SetCapabilities
πŸ‘€ Prompt Template UserPrompt Template UserRun templates, see AI field icons.
πŸ§‘β€πŸ’» Prompt Template ManagerPrompt Template ManagerCreate & manage templates in Setup.
βœ‰οΈ Sales Email UserEinstein Sales EmailsDraft 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

PrincipleDescription
✍️ Clarity & BrevityWrite concise, natural-language instructions.
πŸ’¬ ConsistencyMaintain tone, word choice, and structure.
🎭 Context / RoleplayGive LLM a persona (e.g., β€œYou are a sales rep…”).
🧱 Triple-Quoted InstructionsSeparate context from commands using """.
πŸ”„ Iterate & TestCompare multiple responses for consistency.
⚠️ Direct InstructionsTell 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.

TechniqueDescriptionExample
πŸ“„ Record Merge FieldLink to object field (Input:Account.Name).Use lead name in email.
πŸ” Related List Merge FieldPull related list in JSON (Related List: Account.Contacts).Include related contacts.
πŸ”„ Flow Merge FieldTrigger Flow logic (Flow:Get_Opportunities_Flow).Fetch dynamic data.
βš™οΈ Apex Merge FieldCall Apex class (Apex:ContactEventsPrompt).Return external API data.
☁️ DMO Merge FieldUse Data Cloud objects.Enrich Salesforce record.
🧩 Record SnapshotUse 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 CaseRecommended 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)

ScenarioGrounding 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