When the customer raises a query regarding the issue they are having with the product, and if they ask for a refund, the support agent needs to go through the terms and conditions of the product sold to give the customer a refund.
So here, if we have the AI in Salesforce Agentforce, it understands the issue and shows the agent a suggestion using a prompt template. The template gives agents options to launch a flow.
In this tutorial, we will learn how to invoke flows from prompt template in Salesforce Agentforce, which will provide some dynamic data to the prompt template.
Invoke Flows From Prompt Template in Salesforce Agentforce
To invoke an apex class, we should have a method with an Invokable method as a notation and a capability type as one of the prompt template types. If this method has the prompt template type, then it is accessible in our prompt template.
Now, to make a flow Invokeable from the prompt template, we need to create a special flow type to use in the prompt template. So, if we go to the flows and try to create a new flow, we will see a new type here.
Here, we will see a new option called template-triggered prompt flow, which invokes it from the prompt template.
Create an Invocable Flow in Salesforce
Now, we will create the template-triggered prompt flow and call it in the prompt template in Agentforce.
Before starting to create the flow, we also want to utilize the same prompt template that was created. This prompt template will be used to summarize the account summary field. It needs the contact details previously provided by the apex class.

Now to create the flow, navigate to Setup -> in Quick Find, search for Flows -> New Flow -> select Start From Scratch -> in Flow Type, select Template-Triggered Prompt Flow -> click the Create button to proceed.
In this flow, we can add instructions, and the flow can invoke from the prompt template.

It is asking for the Input Type, so I have selected Automatic Inputs because we are taking input from prompts. Then, which Prompt Template Type is going to invoke this flow? So we are saying that it will be a Field Generation Template Capability.
After that, we need to select the object for that prompt template. Here is the Account.

Now, if you click on the plus icon, we will see something new. We have an additional Add Prompt Instruction. That means when you click on the add instruction option, you can actually add instructions. It has all the other actions, like creating records and getting records.

The apex class previously provided the contact details. But now, in the template-triggered prompt flow, you will see that we have used the field generation template capability with an account object. So here, we are first getting the contact records.
Now, when the prompt template invokes this flow, it will pass the account record to it. This means the input to the prompt template will also be passed as input to this template trigger prompt flow, so we can utilize that input to get the contacts.
So here, I’m adding a Get Record element. After that, provide the Label for the element, and the API Name will be automatically populated.
- Object: Select the object from which you want to retrieve records. Here, I have selected the Contact object.
- Filter Condition: We want to find contacts related to the parent object record. In other words, we want to find the soft drink orders whose account ID is equal to the prompt template’s ID.
- How many records to store: Here, we want to store all records.
How do we get the prompt templates’ input? You can get the account record from the input element. Here, you will see the related entity and then the ID.
We are saying that we should get all the contacts whose accounts match the accounts passed by the prompt template to this flow. So, because of this, we will find all the soft drink orders.

Now, we are iterating over all the contacts found in the get record element, adding instructions for each record.

To add the instruction, click the Add Element icon. For example, the account details are, and then you can pass some dynamic information. The number of times you’re using this add prompt instruction. It keeps adding on top of the previous instruction.
If I have used it here and specified some instructions, and if I use it again after a few blocks, then it will add the response on top of the previous response. So it is kind of an additive operation, which means that the instructions keep adding to the previous instruction.
Now, when you add an instruction, it continues adding to the previous instruction. So here we are, providing prompt instructions with contact details, including name and industry. You can also add merge fields here.
The loop variable currently has the contact record, which records the dot name and then the industry. So, it will add one instruction in the response, and when the loop repeats, it will add the second instruction to the same response. So now the response has two rows with the contact details.

When this flow ends, all the responses will be collected and sent back to the prompt template. So, let’s just save it and activate it. Flow Label: Prompt Template Triggered Flow.
Now, we have a template-triggered flow created for a record-generation type of prompt template, which means that this flow should be visible for all prompt templates that generate records.

Add Flow to Prompt Template in Agentforce
Now, let’s go to the prompt builder and refresh the page. We want to keep the same instruction at the top, but instead of using the apex class, we want to use the flow.
We will find it in the Resource section because we have an active flow. As you click on the flows, you will see the flow you created and the name you provided. You need to add the flow to the prompt template.

Proof of Concept
In the preview, you can see we provided an account name to the prompt template. The prompt template now passes this account name to the Template-Triggered Prompt Flow we created.
Their related contact will be fetched, and according to the instruction that we added in the flow, the details will be visible in the prompt template response.

In this way, we can invoke the flows from the prompt template in Salesforce Agentforce.
Conclusion
I hope you have got an idea about how to invoke flows from a prompt template in Salesforce Agentforce, which gives some dynamic data to be provided to the prompt template.
You may like to read:
- Agentforce for Developers in Salesforce
- Create Agentforce-Enabled Scratch Orgs From Salesforce Developer Edition
- Salesforce Employee and Service Agent in Agentforce
- Build Sales Email Prompt Template in Salesforce Agentforce
- Introduction to Model Builder in Salesforce Agentforce
I am Bijay Kumar, the founder of SalesforceFAQs.com. Having over 10 years of experience working in salesforce technologies for clients across the world (Canada, Australia, United States, United Kingdom, New Zealand, etc.). I am a certified salesforce administrator and expert with experience in developing salesforce applications and projects. My goal is to make it easy for people to learn and use salesforce technologies by providing simple and easy-to-understand solutions. Check out the complete profile on About us.