Salesforce Agentforce: Create Custom Action Using Flow & Assign to Agent

After creating a service agent in Salesforce Agentforce, when a user asks a query or question to an agent, the agent understands and processes information, takes action to perform tasks, and responds to the user.

These actions enable agents to process queries and provide accurate responses. I have created a service agent and deployed it to the community site to assist customers in resolving their queries.

There are different ways to create custom actions in Agentforce. In this tutorial, we will learn Salesforce Agentforce: create custom action using Flow & assign to agent.

In this section, I will explain what a custom action is and, after creating custom actions using Salesforce Flow, how to assign them to AI agents in Salesforce.

Custom Actions in Salesforce Agentforce

The work behind the scenes of an agent is due to actions. Actions actually perform the task, such as creating a draft order, booking an appointment, or fetching record details.

There are some standard actions that the agent can perform. If we want to customise new actions, which are custom actions, we can create them using Apex, Flows, or Prompt Templates.

We will create standard and custom actions in the system according to the organisation’s needs, each solving a particular task.

  • Standard Actions: When we enable the agent, the actions already provided by Salesforce are standard actions.
  • Custom Action: Salesforce users create custom actions according to business needs to solve tasks specific to the organisation.

The following are ways to create custom actions in Salesforce:

  1. Apex: Salesforce programming language.
  2. Flows: No code Salesforce automation tool.
  3. Prompt Template: Reusable prompts written with natural language.

Salesforce Agentforce: Create Custom Action Using Flow & Assign to Agent

In the steps below, I will explain how to create a custom action using a Salesforce flow so that when agents need automation, the flow can be used as a custom action.

For example, we have a service agent deployed on the community site, so that if a customer wants to place an order for soft drinks, they can give a prompt, and the order will be created.

To place the order, we need to create an action, which I have created using Salesforce Apex and assigned to an agent.

In the image below, you can see that the Agentforce service agent has created an order in the Soft Drink Orders custom object.

Salesforce Agentforce: Create Custom Action Using Flow & Assign to Agent

Now, if the customer wants to know the order status, we also need to create an action and assign it to the AI agent so that it can respond to the customer.

In the image below, you can see that when the customer prompts the agent to check the order status, the agent is unable to perform this action because they are unable to retrieve the order status.

how to create custom agentforce agent

Create a Flow in Salesforce to Create an Agent Action in Salesforce

Now, we will create the action using a flow that retrieves the order details for the customer who has provided the order number and sends the details to the agent, allowing the agent to respond to the customer. To know the status of the order.

To create the flow, go to Setup -> in Quick Find search for ‘Flows‘ -> click the New Flow button -> select Start From Scratch -> Autolaunch Flow(No Trigger) -> Create.

Create Custom Action for Agent Using Salesforce Flow
Important: To use the flow as an action for the AI agent, we must select 'Autolaunch Flow (No Trigger)'; except for this flow, no other flow can be used as an action for an agent in Salesforce Agentforce.

1. Create a Variable in Flow: Take the Order Number as Input

First, we need to create a Variable from a New Resource so that we can take input from the customer, whatever they provide, the order number, to pass the flow. Then the flow will automate the process for that record.

As you click the Resource Type dropdown field, you will see various resources, such as Variable and Text Template. Here, we need to select the Variable.

Now we need to provide the details for the following fields:

  • API Name: I have provided the name as orderNumber, which will accept the order number that the customer has provided.
  • Description: This description will be reflected in the Agentforce builder as an instruction for an agent when we assign the action to the service agent.
  • Data Type: The data type will be Number.
  • Availability Outside the Flow: We must check the Available for input option. So that this variable can accept the customer’s order number.
what is the importance of action instructions when creating a custom agent action

2. Create a Variable in Flow: Give the Response to Agent as Output

Again, we need to create a variable to store the retrieved status of the order and provide it to the agent, so the agent can respond to the customer.

  • API Name: Response.
  • Data Type: Since the status field is a string, the data type will be Text.
  • Availability Outside the Flow: We must check the Available for output option. This variable can store the order status and pass it to the AI agent.
add a flow as an agent action

3. Get Record Element: Retrieve Order Details From Object

Now we need to retrieve the record details according to the order number that the customer has provided. For that, we need to add the Get Records element and enter a Label and API Name.

Then we need to select the object from which we want to retrieve record details. Here, I have chosen the Soft Drink Order object, where we have stored all orders and their details.

salesforce agentforce actions

Now we need to add the filter condition so that we can retrieve only the order record for which we provide the order number.

For that, in the Field, we need to use the Order Number field from the Soft Drink Order object, which stores the customer’s order number.

Then, in the Value, we need to provide the orderNumber variable that we created, which passes the order number to the flow that the customer has provided.

Since there will be only one record for each order, we only need to store the first record.

Salesforce Flow For Agentforce Agent Action

In the previous step, we retrieved the order details for the order number provided by the customer.

Now we need to pass the status of the retrieved order number to the agent so that the agent can respond to the customer. To store the status, we created a variable named Response.

action instructions agentforce

Now we are ready to save the flow. To do this, click the Save button, provide the flow Label, and the API Name will be automatically populated. Provide a Description, which will be reflected in the agent action as an instruction.

 Then activate the flow.

Create Agentforce Custom Actions

Create a Custom Action for an AI Agent in Salesforce Agentforce

Now, let’s create a custom action using the flow we’ve created, so that when the customer asks a query or question about their order status, the agent can perform tasks and respond accordingly.

For that, go to Setup. In the Quick Find, search for Agentforce Assets. Click on Actions, and there you will find all the standard and custom actions. To create a new action, click the + New Agent Action‘ button.

Create Custom Action for Service Agent in Salesforce Agentforce

Fill in the details below:

  • Reference Action Type: Previously, we selected Apex; now, as we are creating actions using flows, we need to choose Flow.
  • Reference Action: Here, select the label you provided in the auto-launched flow we created.
  • Then, the Agent Action Label and API Name will automatically populate.

Then click the Next button.

Add Salesforce Flow as Custom Action to Service Agent in Agentforce

So here, we need to provide instructions to the agent. In Agent Action Instruction, we have already described the flow, which will be automatically populated as an instruction here.

After that, provide the Loading Text so that at the time the agent performs the action, this text will display on the conversation window.

Agentforce Agent Action Instruction in Agentforce

Next, we have an input field and an output field. For these fields, instruction is also automatically populated from the flow’s description.

Then, for the input we are collecting from the customer. For the output, we need to show the status to the customer, so the ” Show in conversation checkbox should be checked with Text as the data type.

Then click the Finish button, and our custom action using the flow has been successfully created.

Input and Output Fields in Salesforce Agentforce Actions

Assign Custom Action to An Agent in Salesforce Agentforce

In the steps below, I will assign the custom action to the Agentforce Service Agent that we created using the flow to display the order status.

For that, navigate to the Setup -> In Quick Find, search for the Agentforce Agents -> Select the Agent for which you want to assign a custom action.

Here, I have selected Agentforce Service Agent, which is a Service Agent. -> Then click on the Open in Builder button to add an action. After that, open the Topic under which you want to assign the action to an agent.

Whenever you want to modify the agent, ensure it is deactivated; otherwise, you will not be able to edit the agent details.

Assign Custom Action to Service Agent in Salesforce Agentforce

Then click This Topic’s Actions tab, click the New button, and select the Add from Asset Library option to choose the action that we created.

Agentforce Service Agent Actions in Salesforce

Then, select the action you want to assign to this agent. You can also choose multiple actions, including both standard and custom options. Then click the Finish button.

Select Action in Salesforce Agentforce

In the image below, you can see the action has been successfully assigned to the service agent in Salesforce.

Important: For the Enstien Agent User doent have permission for the Object and the Flows that we craeted for the you need to check the user has assgined to this agent an then give the appropriate permission to user using permission set.

Finally, activate the agent.

Add Custom Action to the Agentforce Agent in Salesforce

In this way, we can create a flow to perform the action by the agent, create the action from the created flow, and assign the custom action to the agent in Salesforce Agentforce, so the customer can receive a response from a service agent.

Proof of Concept:

Now again, as I navigate to the community site where we have deployed the service agent and give the prompt to check the status for the order, you can see the agent is able to retrieve the status from the object and display it to the customer.

Salesforce Flow Action Assign to Agent in Agentforce

Conclusion

 I hope you have an idea about how to create a custom action using Flow for Agentforce in Salesforce. Utilising the use case, I have explained what a custom action is, which flow supports creating custom agent actions, how to create a flow, how to create a new action, and how to assign custom actions to agents in Salesforce after they have been created.

You may like to read:

Salesforce AgentForce Live Webinar

Agentforce in Salesforce

DOWNLOAD FREE AGENTFORCE EBOOK

Start with AgentForce in Salesforce. Create your first agent and deploy to your Salesforce Org.

Salesforce flows complete guide

FREE SALESFORCE FLOW EBOOK

Learn how to work with flows in Salesforce with 5 different real time examples.