What Prompt Builder Is For
Prompt Builder is Salesforce’s authoring tool for reusable AI prompts. You design a template once — with merge fields, grounding queries, and instructions — and then invoke it from Flows, Apex, Agentforce actions, or Lightning components.
The alternative is hand-building prompts inside Apex or Flow. That works for prototypes and falls apart in production when you need to change the prompt and the code in 14 places.
The Four Template Types
Each template type is tuned for a specific shape of job. Pick the wrong type and you’ll fight the product.
1. Sales Email
Generates a personalized email from a Lead or Contact record. Use it in Lightning email composers for reps who want a draft to edit.
Grounding: record fields, related activity, optional knowledge articles.
2. Field Generation
Populates a specific field on a record — say, an “AI Summary” field on Opportunity. Invoked from the Lightning page or a Flow.
Grounding: the target record and anything related you specify.
3. Record Summary
Produces a multi-line summary of a record for display in the UI. The output is rendered directly in a Lightning component, not stored.
Grounding: record + related lists.
4. Flex
Generic, untyped. Takes any inputs you define. Use it when the other three don’t fit — for instance, an agent action, a batch process, or a Flow step that returns structured JSON.
Writing the Template
Every template has three parts: the resources (inputs), the prompt, and the response configuration.
Resources
Resources are the variables available to the prompt. For Field Generation templates, the main resource is the target record. You can add merge variables for related records, Data Cloud CDOs, or even the output of Apex invocables.
Resources are referenced in the prompt with {{!Input:Record.Field}} syntax.
The Prompt
The prompt is a multi-line instruction. It’s written in natural language with merge fields. Keep three things in mind:
Instructions first, data second. Start with what the model should do, then provide the data. This is how LLMs are trained to read prompts.
Be specific about format. “Return a two-paragraph summary” is better than “summarize this.” “Return a JSON object with risk and reason keys” is better than “explain the risk.”
State constraints explicitly. If the output must not exceed 280 characters, say so. If it must not mention competitor names, say so. The model will not infer your corporate PR policy.
Response Configuration
You pick the model (choose the default unless you have a reason), set max tokens, and decide whether the Trust Layer should strip masking tags on the way out.
For structured output (JSON), use a Flex template and validate the response on the Apex side. Prompt Builder will not guarantee valid JSON by itself.
Grounding Patterns
Grounding is how you give the model the data it needs. Three patterns cover most cases.
Pattern 1: Record Fields Only
Simplest. Merge fields from the target record directly into the prompt. Fine for templates that summarize or draft from a single record.
Pattern 2: Record + Related Lists
Use the related records resource to pull in, say, the last 10 activities on an Opportunity. The merge syntax supports iteration:
{{#Input:Record.Activities}}
- {{Subject}} ({{ActivityDate}}): {{Description}}
{{/Input:Record.Activities}}
Keep related-list counts bounded. Pulling 100 activities into a prompt burns tokens and dilutes the model’s focus.
Pattern 3: Data Cloud Grounding
The powerful one. Query a Data Cloud insight or search index and merge the results into the prompt. This is how you give an agent access to structured data that doesn’t live in CRM — say, product catalogs or historical case trends.
Data Cloud grounding is configured in the template under Resources → Add Data Cloud CDO.
Testing Templates
Prompt Builder has a test panel on the right side. Pick a sample record, run the template, inspect the output. Run 20–30 samples spanning the range of inputs you expect in production.
Specifically test:
- Records with sparse data (most fields empty)
- Records with unusual values (very long text, special characters)
- Edge-case relationships (missing parent record, zero related activities)
- Records that should trigger Trust Layer masking
If the template misbehaves on any of these, fix it before shipping. Users will hit every edge case within the first day of release.
Versioning and Change Management
Templates are metadata. You can deploy them through change sets, package them into managed packages, and version them in source control via the Salesforce CLI.
A practical discipline: every change to a production template should be reviewed by someone other than the author. The non-obvious failure mode is a well-meaning edit that changes tone or removes a constraint and nobody notices until QA complaints pile up.
Common Failures
Hallucinated fields. The model invents data that isn’t in the grounding. Fix: tighten the prompt (“Only use data present in the provided record; if a field is empty, write ‘not available’”).
Tone drift. Early responses sound right; later ones drift into generic marketing speak. Fix: add tone guardrails to the prompt and include one or two few-shot examples of the desired style.
Leaked masking tags. The response contains <EMAIL_1> or similar. Fix: check the response-processing setting; the Trust Layer should reinsert originals unless you’ve explicitly told it not to.
Too long / too short. The max-token setting is a ceiling, not a target. Specify a length in the prompt (“in 3–4 sentences”) if length matters.
When Not to Use Prompt Builder
For one-off experiments and developer-facing tools, just call the LLM directly from Apex. Prompt Builder shines when a prompt is shared across multiple surfaces — a prompt used in one place once is overhead.
Frequently Asked Questions
Can I call a template from Apex?
Yes. Use the ConnectApi.EinsteinLLM namespace or, more commonly, wrap the template as an invocable action and call it via Flow.Interview.
How are templates secured?
Templates are metadata; permission is granted via the Prompt Template Management permission. Runtime execution uses the running user’s field-level security.
Can the same template serve multiple object types?
Not directly — a template targets one object. To share logic across objects, extract the stable parts into a Flex template invoked from per-object wrappers.
Is there a template marketplace?
Salesforce ships a growing library of pre-built templates in Setup → Prompt Templates → Install from Template Gallery. Review and customize before deploying — gallery templates are starting points, not finished products.