How To Build Flex and Field Generation Prompt Templates in the Prompt Builder
Prompt engineering is one of the most important skills of our era. With the speedy adoption of AI Large Language Models, the use of language became a very important skill again. One could argue that effective natural language writing will potentially be more important than coding in the future. Prompt writing is also critical for Salesforce Agentforce.
While writing in English – or any other language that the LLM understands – is important, we need to keep in mind how LLMs work so that we can design well-written instructions, establish guardrails, and ground our prompts to produce accurate results.
Writing prompts is not necessarily a Salesforce skill. This is now a universally sought-after skill that everyone needs to master.
Introduction to Prompt Builder
Prompt Builder is a tool to facilitate the creation of AI prompts within Salesforce, enabling users to automate responses based on specific data inputs. This tool is essential for reducing inefficiency when delivering results, thereby increasing operational efficiency across various business functions.
Integration with Salesforce Flow and Apex
Prompt Builder is very well integrated with Salesforce Flows and Apex. This integration allows for excellent customization and functionality expansion, enabling users to execute sophisticated prompts through elaborate workflows and automate intricate tasks. Additionally, it facilitates simple data retrieval from multiple sources, including Salesforce’s Data Cloud and external APIs.
Salesforce Prompt Template Types
Here are all Salesforce Prompt Template Types:
- Einstein AI-Generated Search Answers
Generates concise answers from indexed content like knowledge articles or documents in response to user queries. - Extract Product Mentions
Identifies and extracts product names or references from unstructured text, such as case descriptions or chat transcripts. - Field Generation
Uses prompt templates to generate content for specific fields on Salesforce records, like call summaries or meeting notes. - Flex
A highly customizable prompt type for general-purpose AI tasks, giving you full control over inputs and outputs. - Knowledge Answers
Retrieves and summarizes information specifically from Knowledge Articles to answer questions accurately. - Record Summary
Creates summaries of Salesforce records, such as Opportunities, Cases, or Contacts, by analyzing record data and related activity.
We will use field generation and flex types for this post.
Real-World Applications
Prompt template is an excellent tool when summarizing the history of a customer and producing recommended actions. This tool can also expedite the process of documenting the actions taken.
🚨 Use case 👇🏼
A coaching organization visits their clients and provides them with career, personal or general consultations. This is a personalized service that requires the consumption of past data and experience the organization has on the client. For this purpose, the organization will build two prompt templates: One that will generate and save preparation notes for the coach in advance of their visit on the record, and another one that will be called from the internal Agentforce panel for the coach’s preparation.
Automating the generation of coaching notes can reduce manual processing time from 30 minutes to under 5 minutes.
Data Model
For this use case, I picked a simple data model. The coaching session object is related to the contact for the client. A coaching session record will be created whenever a session is scheduled or delivered. The status field determines whether a session is scheduled or completed. When a new session is scheduled, the date and time of the session is stamped via a record-triggered flow on the client contact record as the next (upcoming) session date and time.
The client contact record also has fields that hold the client’s subscription information and their interests.
Most importantly, all the past coaching session notes need to be considered when preparing for the next session.
Field Generation Prompt Template
The coaching session object includes the preparation notes rich text field. When a new coaching session is scheduled a new record is created. Before the coach goes to this session, they can go into this record and generate preparation notes for their upcoming session.
Field Preparation and Field Generation Prompt Template Creation
Field generation prompt template receives the coaching session record as input. When setting up this prompt template type, you need to scope it for a text or rich text field. Therefore, remember to create this field before you open your prompt builder. In this case, we will scope this prompt template for the preparation notes rich text field.
Record Input
Your prompt template will access all field values of the record it is built on. You can also traverse to related records. You can use field values of the parent records, but referring to related records this way is not very helpful. Your prompt template cannot see a meaningful summary of the related records.
Template-Triggered Prompt Flow Input
This is where flow input comes in handy. You can create a Template-Triggered Prompt Flow and make that flow accessible from your prompt template. Based on my experience, I can say it is quite tricky to make this flow available inside your prompt builder resource picker. I think there is a bug that is scheduled to be fixed soon, that is preventing the flow from showing up in the prompt builder in some cases.
For this use case, I built a flow that retrieves all the past completed coaching sessions and pastes the relevant information into the prompt for the template to consume.
Building the flow is not that difficult, but you will need to loop if you want to summarize multiple records.
Here is how you build the flow:
- Start a Template-Triggered Prompt Flow.
- Configure the start element: Choose Automatic Inputs, Field Generation Template Capability Type and point your start element to the Coaching Session object.
- Get all completed coaching sessions related to the same contact on the triggering record.
- Loop the coaching sessions.
- Add an Add to Prompt element inside the loop, and include the relevant field values in the prompt. Here is what mine looked like:
---Here is one completed past coaching session details: Title: {!Loop_Sessions.Title__c}Preparation Notes: {!Loop_Sessions.Preparation_Notes__c}Session Notes: {!Loop_Sessions.Session_Notes__c}Duration (in hrs): {!Loop_Sessions.Duration__c}Status: {!Loop_Sessions.Status__c}---
- Add another Add to Prompt element outside the loop before the end of your flow and add the following text. This is important for when no prior completed records can be found.
There are no other completed coaching sessions found for this client.
- Save, debug and activate your flow.
This is what your flow should look like.
Writing the Prompt Template Instructions
Important things to watch for:
- There are effective reusable instructions you will want to save for the future. Therefore, create a text document and save general instructions and guard rails into this document. You can paste these into your future templates later.
- Start with, “Your job is,” and give the LLM a job description.
- Continue with context to ground. Drop in relevant field values here. Remember to pick your field values using the resource picker.
- Then give the template a summary of the past history from the flow. You should be able to see your flow in your resource picker. If you cannot, you may need to save, deactivate, reactivate, try a few things. I had difficulty getting this done to be honest.
- The large language model does not understand checkbox values or picklists automatically. You need to define and explain what these values mean, and what actions need to be taken.
- As you write these, be sure to set clear guidelines and include both what to do and what to avoid. Additionally, specify how the response should be structured to keep everything consistent and easy to follow. For example:
- We are writing for a Salesforce Rich Text Field, so you’ll need to follow this guidance below:
- Provide output in HTML format. Only Output the text inside the tag pair.
- Use bullets or numbered lists to highlight key points.
- Enhance readability by adding rich text formatting (i.e., font, text color, background color, etc.) where possible.
- Add HTML tags to improve readability.
Save your prompt template and test it. Save a new version when needed. You will need to point the prompt template to an existing record in Salesforce, therefore create a coaching session record before you test. Read the resolution and response carefully. Make iterations and improve the template. Save and activate your work.
Field Generation Prompt Template Content
Here is my complete prompt template content. You can copy and paste this to get started. Remember to delete the inputs, and insert them from your resource picker for accuracy.
Your Job is to provide a note and guidance for the Coach on what they need to know for an upcoming Coaching Session. This response will be used to populate the session preparation notes field on the Coaching Session record.Use the following context to ground your final responseContext:Client's Name: {!$Input:Coaching_Session__c.Contact__r.Name}Client's Birthday: {!$Input:Coaching_Session__c.Contact__r.Birthdate}Client's Next Scheduled Session Date: {!$Input:Coaching_Session__c.Contact__r.Next_Scheduled_Session__c}Is Client a Subscriber: They are if the value of is true.Client's Subscriber Type: {!$Input:Coaching_Session__c.Contact__r.Subscriber_Type__c}Client's Interest Areas: {!$Input:Coaching_Session__c.Contact__r.Interests__c}Recent coaching sessions (these are the recently completed coaching session notes separated by "---", extract past experience and interests): {!$Flow:Coaching_Session_PTF_Past_Completed_PT_Flow.Prompt}Note on Subscriber Types:There are three types: "Career", "Personal" and "General"- "Career" focuses on progress and advancement at the work place- "Personal" focuses on wellbeing and happiness outside of work.- "General" is a healthy mix of the two other types.Note on Session Types:There are 2 types of Session Types Inaugural (first) and Follow-up sessions. Specify which type is relevant and the duration of the session. If there are one or more than one completed past coaching session records, then the Follow-up session type will be used, otherwise Inaugurual will be set up.- Inaugural: If the client does not have any previous consultation on record, then this format will be used. This coaching session will be guided toward setting up a plan with the client. Discussions should be centered around making sure they have the proper readiness to start, discussing their interests, discussing their past experience, providing them with a few guidance tips on getting started, and telling them what to expect. Usually go for 1.5 hour. A follow-up is usually scheduled for one month after the first one (this session).- Follow-up: These sessions are monthly check-ins with the customers to review their progress and answer questions for them based on what they are dealing with. Usually go for 1 hour.Note on birthdays: Customers with upcoming and past birthdays, within 30 days of the next session scheduled date ( {!$Input:Coaching_Session__c.Contact__r.Next_Scheduled_Session__c}) will get a free digital book. Please add this detail into the notes if the birthdate is within 30 days of the next scheduled session. If no birthday is provided on the client contact record, or the birthdate is not within 30 days of the next scheduled session do not include this information.- If {!$Input:Coaching_Session__c.Contact__r.Is_Subscriber__c} value is false then the client is not subscribed. Warn the coach: Include a message saying confirm subscription before visit. If the client is subscribed (value = true) do not include a message for the coach about this.Response:- Your response should give the coach information to go into the consultation and know what to discuss with the customer.- Your response should contain important information about the customer, their interests, structure on how the coaching session should go, guidance for their client based on interests and past experience.- Use break-lines in your response to segment between different ideas- We are writing for a Salesforce Rich Text Field, so you'll need to follow this guidance below:- Provide output in HTML format. Only Output the text inside the tag pair.- Use bullets or numbered lists to highlight key points.- Enhance readability by adding rich text formatting (i.e., font, text color, background color, etc.) where possible.- Add HTML tags to improve readability
Adding the Prompt Template to the Page Layout
Once the prompt template is finished, you need to add the prompt template to the page layout. Go to the object lightning page layout, activate dynamic forms if not already active, pick the preparation notes field and link it to the prompt template you have created.
Field Generation Result
Here is the result of the field generation prompt template on the record.
Flex Prompt Template
Flex prompt template is a more powerful tool. You can set it up using the prompt text you have already created. Flex prompt template can accept up to five different inputs of various different types. They can be built into Agentforce actions and used by Agentforce topics.
Currently, prompt template inputs cannot be changed once configured. You will need to create a new prompt template if you want to change inputs. Therefore, always add at least one free text input when configuring a flex prompt template. This will give you the flexibility you need, if you need to add additional instructions or data to your prompt.
Object Preparation and Flex Prompt Template Creation
The input types you can use, when creating a flex prompt template are:
- Object
- Free Text
- Data Model Object
For this template type, you can input any object you want. They don’t have to be related. You need to makes sure you create you object before you build your template, if you are working with custom objects.
You also don’t specify fields when you build a flex template. Your template will have access to all the fields on the record that will be inputted into the template.
Flex Template Inputs
For this use case we will use three input variables:
- Coaching Session Id
- Client Contact Id
- Free Text Input
We could use just the coaching session Id here, but the additional inputs will give us flexibility in how we process different scenarios. For example: We may decide to use this prompt template even before the first session is scheduled, therefore prompt template could work just by receiving the client contact Id.
Reuse Template Triggered Flow Input
I found that I can reuse the same flow I created for the field generation prompt template. This flow should be accessible for you in your resource picker, when you are building your prompt.
Writing Flex Prompt Template Instructions
The prompt template content for this will be very similar to the field generation example. The main difference will be that you will refer to three inputs and the flow input for this template type. You can start with your own template from the previous example and modify it to fit the needs of the flex template. Or you can use my content provided in the code block below to get started.
Once you finish your first pass, save your prompt template and test it. Save a new version when needed. You will need to point the prompt template to existing records in Salesforce, therefore create a coaching session record before you test. You can add additional data and instructions in the free text input field. Read the resolution and response carefully. Make iterations and improve the template. Save and activate your work.
Flex Prompt Template Content
Here is my complete prompt template content. You can copy and paste this to get started. Remember to delete the inputs, and insert them from your resource picker for accuracy.
Your Job is to provide a note and guidance for the Coach on what they need to know for an upcoming Coaching Session.Use the following context to ground your final responseContext:Client's Name: {!$Input:ClientIdVar.Name}Client's Birthday: {!$Input:ClientIdVar.Birthdate}Client's Next Scheduled Session Date: {!$Input:ClientIdVar.Next_Scheduled_Session__c}Is Client a Subscriber: They are if the value of {!$Input:ClientIdVar.Is_Subscriber__c} is true.Client's Subscriber Type: {!$Input:ClientIdVar.Subscriber_Type__c}Client's Interest Areas: {!$Input:ClientIdVar.Interests__c}Recent coaching sessions (these are the recent completed coaching sessions that will give you interest and past experience information):{!$Flow:Coaching_Session_PTF_Past_Completed_PT_Flow.Prompt}Note on Subscriber Types:There are three types: "Career", "Personal" and "General"- "Career" focuses on progress and advancement at the work place- "Personal" focuses on wellbeing and happiness outside of work.- "General" is a healthy mix of the two other types.Note on Session Types:There are 2 types of Session Types Inaugural (first) and Follow-up sessions. If there are one or more than one completed past coaching session records, then the Follow-up session type will be used, otherwise Inaugural will be set up.- Inaugural: If the client does not have any previous consultation on record, then this format will be used. This coaching session will be guided toward setting up a plan with the client. Discussions should be centered around making sure they have the proper readiness to start, discussing their interests, discussing their past experience, providing them with a few guidance tips on getting started, and telling them what to expect. Usually go for 1.5 hour. A follow-up is usually scheduled for one month after the first one (this session).- Follow-up: These sessions are monthly check-ins with the customers to review their progress and answer questions for them based on what they are dealing with. Usually go for 1 hour.Note on birthdays: Customers with upcoming and past birthdays, within 30 days of the next session scheduled date ( {!$Input:ClientIdVar.Next_Scheduled_Session__c} ) will get a free digital book. Please add this detail into the notes if the birthdate is within 30 days of the next scheduled session. If no birthday is provided on the client contact record, or the birthdate is not within 30 days of the next scheduled session do not include this information.Note on Recent Coaching Session records: The recent orders should contain client's interests and past experience.If there are additional notes, they will be provided in {!$Input:FreeTextVar}. Please take these into consideration.Response:- If {!$Input:ClientIdVar.Is_Subscriber__c} value is false then the client is not subscribed. Warn the coach: Include a message saying confirm subscription before visit. If the client is subscribed (value = true) do not include a message for the coach about this.- Your response should give the coach information to go into the consultation and know what to discuss with the customer.- Your response should contain important information about the customer, their interests, structure on how the coaching session should go, guidance for their client based on interests and past experience.- Use break-lines in your response to segment between different ideas- We are writing for a Salesforce Rich Text Field, so you'll need to follow this guidance below:- Provide output in HTML format. Only Output the text inside the tag pair.- Use bullets or numbered lists to highlight key points.- Enhance readability by adding rich text formatting (i.e., font, text color, background color, etc.) where possible.- Add HTML tags to improve readability
Adding Your Flex Prompt Template to Agentforce
I will cover this topic in an upcoming post.
Conclusion
As artificial intelligence continues to redefine the landscape of business processes, tools like Salesforce’s Prompt Builder stand at the forefront of this technological revolution. The insights provided by Jaswinder Rattanpal at TrailblazerDX 2025 inspired this demo and the post. There is no doubt everyone needs to master prompt engineering to prepare for the AI future.
For Salesforce users and enthusiasts looking to discover more about the capabilities of Prompt Builder, the platform provides comprehensive learning and support through Trailhead, hands-on workshops, and a vibrant community forum. Finally, remember to check back at Salesforce Break for additional posts on Prompt Templates and Agentforce AI.
Explore related content:
Salesforce AI: Transforming Data into Sales Engagement
New Agentforce Specialist Certification
How to Get Your AI-Powered Enhanced Developer Org with Agentforce and Data Cloud
#Agentforce #AI #AISpecialist #Einstein #PromptBuilder #Salesforce #SalesforceAdmins #SalesforceDevelopers