Invoke Flows From Prompt Template in Salesforce Agentforce : Bijay Kumar

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



**Summary:** This content provides a tutorial on how to invoke flows from a prompt template in Salesforce Agentforce. It explains how to use data from CRM records (sObjects) and an Apex class to enhance the functionality of prompt templates. The tutorial details the steps to create a template-triggered prompt flow that can dynamically retrieve and display account-related contact information. ### Key Details: 1. **Prompt Template Creation**: The tutorial starts with the creation of a prompt template that utilizes account data, including account name, rating, and type. 2. **Invoking Flows**: It explains how to invoke an Apex class with an invocable method and how to create a special flow type called "template-triggered prompt flow" to be used within the prompt template. 3. **Flow Creation Steps**: - Navigate to Setup and create a new flow. - Select "Template-Triggered Prompt Flow" and set it up to take input from the prompt template. - Use the account object to retrieve related contact records. 4. **Dynamic Data Handling**: The flow retrieves contact details related to the account, allowing the prompt template to display this information dynamically. 5. **Instructions Addition**: The tutorial describes how to add instructions and merge fields to build a comprehensive response based on the retrieved data. ### Conclusion: The tutorial concludes by summarizing the process of invoking flows from a prompt template, emphasizing how this feature allows for dynamic data retrieval in Salesforce Agentforce. ### Additional Context: Salesforce Agentforce is a platform that enables businesses to streamline their customer relationship management processes. Understanding how to use flows and prompt templates effectively can greatly enhance the user experience and operational efficiency. ### Hashtags for SEO: #Salesforce #Agentforce #CRM #PromptTemplate #ApexClass #DynamicData #FlowCreation #SalesforceTutorial #TechTips #SoftwareDevelopment


After creating our first prompt template, which is grounded with CRM data coming from the sObjects and an apex class, the account name, account rating, and account type come from the account record itself. We also have some data coming from the apex class.

In this tutorial, we will learn how to invoke flows from prompt template in Salesforce Agentforce, which will give some dynamic data to be provided into 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 have a special flow type that we should create in order to use in the prompt template. So, if we go to the flows and try to create a new flow, then you will see a new type here. Here, we will see a new option called template-triggered prompt flow, which means that it is invoked from the prompt template.

Create an Invocable Flow in Salesforce

Now, we will create the template-triggered prompt flow so that we can 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.

Prompt Template Builder in Salesforce

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 Create button to proceed.

In this flow, we can add instructions, and the flow can invoke from the prompt template.

Create Flow to call from Prompt Template in Salesforce

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.

Template Triggered Prompt Flow in Salesforce

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.

Instruction Element in Salesforce Flow

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 an 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 from which object you want to retrieve records. Here I have selected 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 templates 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.

Create Prompt Template Flow in Salesforce

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

Loop Element in Salesforce Flow

To add the instruction, click the Add Element icon. For example, account detail is and then you can pass some dynamic information and the number of time you’re using this add prompt instruction. It keeps on adding on top of the previous instruction.

If I have used it here and specified some instruction, 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 on adding on top of the previous instruction.

Now, when you add an instruction, it keeps adding to the previous instruction. So here we are, providing prompt instructions with contact details, including name and industry. You also can 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.

Invoke Flows From Prompt Template in Salesforce Agentforce

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.

Prompt Template Triggered Flow in Salesforce

Now, let’s go to the prompt builder and refresh the page. Here, 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. You will see the flow you created and the name you provided as you click on the flows. You need to add flow in the prompt template.

Invoke Flow from Prompt Template in Salesforce

In the preview, you can see we provided an account name to the prompt template. Now, the prompt template passes this account name to the Template-Triggered Prompt Flow that 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.

Prompt Builder in Agentforce

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 into the prompt template.

You may like to read:

The post Invoke Flows From Prompt Template in Salesforce Agentforce appeared first on SalesForce FAQs.


March 28, 2025 at 05:56PM
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