Create Custom Action Using Flow For Agentforce in Salesforce

After creating a new agent in Salesforce Agentforce, when a user asks a query or question, the agent understands and processes the information, takes action to perform tasks, and responds to the user. These actions enable agents to process queries and provide accurate responses.

There are different ways to create custom actions in Agentforce. In this tutorial, we will learn how to create a custom action using Flow for Agentforce in Salesforce.

In this, using the use case, I will explain what a custom action is and, after creating custom actions, how to assign them to 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.

We will create standard and custom actions in the system according to the organisation’s needs, each solving a particular task. Custom actions can be created using Flows, Apex, and prompt templates.

  • 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.
  4. External Services: No-code connection to external API.

Create Custom Action Using Flow For Agentforce in Salesforce

In the step below, I have created a custom action using a Salesforce flow so that when agents need automation, the flow can be used as a custom action.

So, let’s take a scenario to create a custom action in Agentforce. The agent has to manually create a task or activity record on an account or any other standard or custom object.

Since users work on multiple accounts, this becomes a lot of clicks for them, so it would be very easy if their AI assistant could do this for them. For that, let’s create a custom action using the flow.

Important: We can only use invokable or auto launched flows to create the custom action to assign to and agents in Agentforce.

1. Create Auto Launched Flow:

Navigate to Setup -> In Quick Find, search for Flows -> Click New Flow button -> Select Auto-launched Flow-> Click Create button.

Create Custom Action for Agent Using Salesforce Flow

Here, I created three text variable resources: RelatedIdSubject, which is available for input, and TaskId, which is kept available for output. In the step below, I have shown an image to create the variable.

Create Custom Action Using Flow For Agentforce in Salesforce

Here, you can see that I created a Variable with Text as the data type, set the available for input, and clicked the Done button.

Custom Agent Action using Salesforce Flow

Then, to assign the task to the record owner, we need to add the Create Record element. Provide details; in the object, select Task object. Below, I have explained Set Field Values for the Task:

  • Due Date Only: In the due date, I have assigned the formula where I set the due date as in the next 3 days when the task is assigned.
  • Assigned To ID: Here, we need to specify to whom we want to assign this task, and I assigned it to the current user.
  • Subject: The subject will be whatever he has sent, and the related ID will become the whatId
Agentforce Custom Actions Using Salesforce Flows

After that, we set the TaskId variable as available for output, added that variable here, and stored the created task record ID. That means it will be shown on the custom action as an output field.

Assign Flow Custom Actions to Agents in Salesforce

After creating the flow, save it and ensure it is activated before using it as a custom agent action in Salesforce Agentforce.

2. Create a Custom Action For Using Flow in Agentforce

Now, we will create a new Agent custom action so that when the user asks any query or question, the agent takes action to perform tasks and responds to the user.

For that, go to Setup. In the Quick Find, search for Agent Action. Click on New Agent Action.

New Custom Action Using Salesforce Flow in Agentforce

Fill in the details below:

  • Referenced Action Type: Previously, we selected Apex; now, as we are creating actions using flows, we need to select Flow.
  • Referenced 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.
Create an Agent Action Using Salesforce Flow

So here, we need to provide instructions to the agent. In Agent Action Instruction, I have provided instructions to the agent so that whenever the agent gets such a prompt, it will be easy for the agent to understand that this action will solve the exact same requirement.

Again, we have an input field and an output field. Here, also, we have to give the instructions. Then click the Finish button.

I have explained how to create an action in Agentforce.

Create Custom Agent Action in Salesforce

As you click the finish button, you can see the Agent custom action has been successfully created.

Create Custom Agent Action using Salesforce Flow

3. Assign Action to Agent in Salesforce

In the steps below, I will assign the custom action to the Einstein Copilot agent that we created using the screen flow to create a task when the agent gets such a prompt.

Before assigning the action to an agent, let’s ask the agent to create a task record for a particular account with a subject. Below the image, you can see the prompt response to the ‘search query isn’t supported’.

Salesforce Flow to Create Agent Actions in Salesforce

Now, let’s assign the created custom action to an agent. For that, navigate to the Setup -> In Quick Find, search for the Agents -> Select the Agent for which you want to assign a custom action.

Here, I have selected Einstein Copilot, which is Agentforce. -> Then click on the Open in Builder button to add an action.

After that, select the Topic to which you want to add the custom action. Then click This Topic’s Actions tab, click the New button, and select the Add from Asset Library option to select the action that we created.

Assign Actions to Topic for an Agents in Agentforce

Then select the Action that you want to assign to this agent. You can also select multiple actions, including standard and custom actions. Then click the Finish button.

Add Actions to a Topic in Agentforce

After assigning the custom action to the agent, I again asked the agent to create a task for the XYZ account with the subject ABC. You can see how the agent responded to a task created with the provided details.

Assign Custom Actions To Agents in Salesforce

Also, as I navigate to the Task object, the new record has been created with the values that we provided in the prompt and the auto-launched flow.

Agent Actions Using Salesforce Flow

In this way, we can create custom actions using flow for Agentforce in Salesforce to automate any task when the agent gets such a prompt.

Conclusion

I hope you have an idea about how to create custom actions using the flow for Agentforce in Salesforce. Using 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 creating them.

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.