Prompt Builder and Prompt Template in Salesforce Agentforce : Bijay Kumar

Prompt Builder and Prompt Template in Salesforce Agentforce
by: Bijay Kumar
blow post content copied from  SalesForce FAQs
click here to view original post



### Summary of Salesforce AgentForce: Prompt Builder and Prompt Templates In Salesforce AgentForce, prompts are how users communicate with the large language model (LLM) to get responses. Effective prompts lead to better outputs from AI, making it crucial to craft them well. This content discusses the **Prompt Builder** and **Prompt Templates** within Salesforce AgentForce. #### Key Details: 1. **Prompts**: These are the instructions given to the AI to perform tasks or provide information. The more specific the prompt, the better the response. 2. **Prompt Builder**: This tool allows users to create prompt templates that can be reused for various tasks. It integrates user data and other relevant information to generate content efficiently. 3. **Prompt Templates**: Pre-designed instructions that guide the AI on how to respond. They ensure consistent answers and can include dynamic values such as customer names or product details. 4. **Types of Prompt Templates**: - **Sales Email Prompt Template**: Generates email drafts using Salesforce data. - **Field Generation Prompt Template**: Populates fields in Salesforce objects (like account summaries). - **Record Summary Prompt Template**: Summarizes records for quick reference. - **Flex Prompt Template**: The most versatile, allowing multiple object details to be included. 5. **Creating a Field Generation Prompt Template**: The process involves selecting template types, naming them, and grounding them with specific data to provide meaningful summaries. 6. **Apex Class for Custom Logic**: Users can create an Apex class to fetch specific data, which can then be used in their prompt templates for tailored responses. ### Conclusion Understanding how to effectively use the Prompt Builder and Templates in Salesforce AgentForce can significantly enhance productivity by automating tasks and improving communication through AI. ### Additional Information: - Effective prompts can lead to meaningful interactions with AI, making it a valuable tool for sales and marketing teams. - Utilizing tools like the Prompt Builder can save time and streamline processes, especially when generating content for customer interactions. ### Relevant Hashtags: #Salesforce #AgentForce #AI #PromptBuilder #PromptTemplates #GenerativeAI #CRM #SalesAutomation #SalesEmail #FieldGeneration #ApexDevelopment #BusinessIntelligence


Whenever you ask an agent a question, the prompts are how you communicate with the large language model (LLM). AgentForce responds to queries and requests in a language inspired by human speech, providing relevant responses.

When we provide a clear and effective prompt, the generative AI gives better results. In this tutorial, we will learn about the prompt builder and prompt template in Salesforce Agentforce. I will also explain how to use prompt templates created through the prompt builder.

Prompt Builder and Prompt Template in Salesforce Agentforce

Below, I will explain the prompt builder and prompt template in Salesforce Agentforce.

Prompts in Salesforce Agentforce

In simple words, prompts are the instructions we give the Agent in the input to retrieve information, perform a task, or take other actions.

AgentForce responds to queries and requests in a language inspired by human speech, providing relevant responses.

Generative AI can give correct output or meaningful answers if it is given effective prompts. Prompts are how you communicate with a large language model (LLM), and designing effective prompts is key to unlocking the benefits of generative AI.

This means that if your prompts are specific, then you will get much better results from the LM model.

Let’s understand this with an example of how effective prompts improve results with an LM model. In OpenAI ChatGPT, I’m asking it to ‘Generate an image of a crowded city,’ and then we will see the difference in the output it generates based on the prompts we have given.

Prompts in Salesforce Agentforce

Now, let me give one more prompt with important information grounded in my needs. So here again I’m asking crowded cities, but this time I want with specific details.

Salesforce Specific Prompt in Agentforce

With this prompt, we can say that AI can provide much more meaningful responses. The difference here is that the first prompt did not have grounded data, but the second prompt does, which is an Indian city.

So, when we added extra or specific information, the response changed completely. That’s why it is vital to have an effective prompt.

Writing an efficient prompt has become crucial when working with LLMs or Gen AI. Now, let’s understand how it will help in Salesforce CRM.

In CRM, the sales rep or the marketing team needs to generate content to send to prospective leads or users. Gen AI is very good at generating content by analysing large amounts of data and summarising them in a precise, clear manner.

Prompt Builder in Salesforce Agentforce

The prompt builder helps us generate a prompt template that can be used in different places. It is very similar to the Copilot builder, where we added different actions and tested how our Copilot was working.

In the prompt builder, we will create the prompt and ground it in user data, object data, or any information we want to pass to the LLM.

  • A prompt builder helps us build trusted generative AI. It creates a prompt template bound to one or more objects to generate summaries or content.
  • For example, the template is generated to send an email to the user, with the account data already embedded. This will definitely save the salesperson a lot of time, as they would otherwise have had to go through the details to draft the email.
  • Using Prompt Builder, we can create more relevant prompts grounded in your business data from CRM, cloud, and external storage.
  • Preview and Version Template: Since it’s a prompt builder, we can build the prompt, test it, preview the response, and, if it is not as per our needs, regenerate it.

What is a Prompt Template in Salesforce Agentforce?

A Prompt Template in Salesforce Agentforce is a pre-designed instruction or message that we give to the AI, so it knows how to think and what output to generate.

Instead of writing long instructions every time, you create a template once, and the AI will follow it whenever the prompt is used. This helps you maintain consistent answers, tone, and structure across different use cases.

When the AI receives a user request, Agentforce uses the Prompt Template we created as a guide. We can insert dynamic values in the prompt template, such as Account Name, Case Details, Product, or Customer Email, and generate the final output.

Different Types of Prompt Templates in Salesforce Agentforce

Below, I will explain different types of prompt templates in Salesforce Agentforce.

1. Sales Email Prompt Template in Agentforce

A sales email template generates email content bound to Salesforce data, such as an email to a contact or a lead. Once these prompt templates are activated, they start showing in the out-of-box draft and email quick actions you would have seen on a record detail page, where we can log a call, create a task, and draft an email.

We can invoke or execute the sales template from the draft and email feature. The draft and email features are available on the record detail page. As you click that, you will see a dropdown where you can select the prompt template you have configured, and it should generate a draft email that the agent can review and edit.

The sales email template can also be invoked via Apex classes, which are also exposed as REST API services. You pass the parameter, and they return the response to the calling application.

2. Field Generation Prompt Template in Agentforce

A field generation template is used to populate values in an object’s field. For example, we can have a field on the account that summarises all the orders placed until now or all the cases created against it. By looking at that agent, we can get a quick overview without going through account-related details.

Like the sales email template, the field generation template can be used on a record page, which means it is bound to a specific field, let’s say the account summary field. On the record page, you can place your summary field and bind it to this template.

Then, any response from this template will be stored in that field. It can also be called via Einstein Copilot, action flow, rest API, and Apex.

3. Record Summary Prompt Template in Agentforce

The record summary template is used only by Einstein Copilot to generate record summaries. We have seen examples of this when we asked the copilot to summarise the lead or any other record.

The summary template is only specific to the Copilot action.

4. Flex Prompt Template in Agentforce

The flex template is the most powerful of these four types. It supports up to five object details, which can be grounded in the prompt template, whereas the sales or field generation templates are only bound to specific record objects.

Create Field Generation Prompt Template in Salesforce Agentforce

In the steps below, I will explain how to create a field generation propt template to store the information.

Suppose we look at the information stored on this account, we see different contacts, opportunities, and cases. We want an account summary field on the account object, with content that summarises the different contacts this account has.

This will help the agent get a quick overview of the account by entering this field. For that reason, I have created a custom field called account summary, which is of type long text area.

Here is a very important point for the field-generation prompt template: since it is bound to a field, the field type should be a text area.

Field Generation Template in Salesforce Agentforce

Now, let’s create the prompt template. Go to Setup -> In Quick Find, search for the Prompt Builder -> This screen is very similar to our Einstein Copilot action screen.

To create a new prompt, click the New Prompt Template button.

Create New Prompt Builder in Salesforce

Now, fill in the details for the new prompt template, as I explained below.

  • Prompt Template Type: We have four types of prompt templates. We need to select the template type you want to create here. I have chosen the Field Generation template.
  • Template Name: After that, provide the name of your template as per your requirement. The API Name will be automatically populated.
  • Description: Give a short intro about your prompt template.
  • Object: Select the object for which you are creating this field generation template. You also need to select the Object Field.

After that, click the Next button to proceed.

Prompt Builder and Prompt Template in Salesforce Agentforce

Now, we need to build our prompt template. Here, we can specify which Model to use, and we should be able to see the preview. For this prompt template, Salesforce offers various LL Models, and we can use any of them.

Since we have seen that the field generation template is for an account object, you should be able to see it in the Resource option.

  • Account: If we need to ground this template with account-related information, we should be able to access it through the Resource option.
  • Current User/Organisation: Similarly, we can add information about the current user and the organisation here.
Prompts and Prompt Builders in Salesforce Agentforce

So here, since we want this template to summarise the account information, we should give our prompt like the one below.

This is where we have to provide specific information about an account, which means that we are grounding the customer data into the prompt template. For that, we need the account name. Click on the Resource -> Account -> Account Name field.

If you want to add more information, you can go to Resources -> Account -> again, where you will find all the account fields.

That means this template now has some static content and will have dynamic content based on the account passed here.

Now, we require that the information we want to feed into the prompt template be available in a third-party system. Maybe the information is a little complicated, requires a SOQL query, or requires custom logic.

After that, we want to feed whatever response we have into the prompt template. So, for such a requirement, you can invoke Appex or flow, and they can return whatever response they give, which will serve as the grounding data for this prompt template.

So, for that, we need to create an Apex class, or you need to have specific flows. Then that apex class or flow will be available for a prompt template.

Create Field Generation Template in Salesforce Agentforce

Apex Class For Prompt Template in Salesforce Agentforce

Below, I have created an Apex class, AccountSummaryPrompt. Just as with our custom actions, if we want the Apex method to be available as a prompt template response, it should be annotated with the Invokable method. Here, this method is available for the record generation template.

Since our prompt template is for an account, the account is the related entity to that prompt template.

After that, save the apex class and navigate to the prompt builder again.

public class AccountSummaryPrompt {
    
    @InvocableMethod(label='Account Details'
                     description='Find Account details')

    public static List<Response> getAccData(List<Request> requests) {
        
        if (requests.size() != 1)  
            throw new IllegalArgumentException('The requests list must contain one entry only'); 
        
        Account acc = requests[0].RelatedEntity;

        List<Account> AccDetails = [SELECT Id, Name, Industry FROM Account WHERE Id = :acc.Id];

        String responseData;
        
        if (AccDetails.isEmpty()) {
            responseData = 'There are no Account records.';
        } else {
            responseData = 'Account Details: ';
            for (Account a : AccDetails) { 
                responseData += String.format('{0}, {1}.', new List<Object>{a.Id, a.Name});
            }
        }

        List<Response> responses = new List<Response>();
        Response res = new Response();
        res.Prompt = responseData;
        responses.add(res);

        return responses;
    }
    
    public class Request {
        @InvocableVariable(required=true)
        public Account RelatedEntity;
    }
    
    public class Response {
        @InvocableVariable(required=true)
        public String Prompt;
    }
}

Now, we need to add the apex class that we created. For that, click the resources -> Apex -> Select the label you provided in the Apex invocable method. That Apex method will return the response as a string, which will be added here.

Salesforce Agentforce Prompt Builder

So, the final prompt, which already includes all this information, will be passed to the LM model.

In the preview panel, we will see what our final prompt has been generated by actually adding this information here. In the response, we will see what response we get from the LM model when we pass that prompt. So, for this one, let’s use a model like OpenAI’s GPT 4.

We have to give a related record to get that account’s name, which will also be passed to our Apex method. So, for that, let’s add our account. Let’s use sForce. You can click on Save and Preview. This is where you will see two pieces of information.

Prompt Template Builder in Salesforce Agentforce

In the preview section, we see this prompt template. After grounding the information, how does it look? We were told to write a short paragraph summary of the account details. The account name is sForce.

You will see that it has grounded that information. The account name is now available here. The account details and the case details are listed below.

Field Generation Prompt Template in Salesforce Agentforce

Conclusion

I hope you have got an idea of the prompt builder and the prompt template in Salesforce Agentforce. I have also explained how to use the prompt templates created through the prompt builder.

Also, I have explained the types of prompt templates and how to create a field generation prompt template in Salesforce AgentForce.

You may like to read:

The post Prompt Builder and Prompt Template in Salesforce Agentforce appeared first on SalesForce FAQs.


November 27, 2025 at 08:42PM
Click here for more details...

=============================
The original post is available in SalesForce FAQs by Bijay Kumar
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.
============================

Salesforce