86 / 100 SEO Score

Invoke Agentforce Agents with Apex and Flow Updated 2026

Invoke Agentforce Agents with Apex and Flow Updated 2026

AgentForce agents can be used for two primary functions for a company: helping employees and messaging customers. Employee-facing agents support employees in boosting productivity levels by performing automations, summarizing information, and aiding in actions within Salesforce, utilizing user permissions. Customer-facing agents, typically placed on websites or mobile apps, are “digital labor,” performing tasks like responding to queries, offering purchasing guidance, or lead qualification using their own unique user profile and permissions.

In the past, interacting with these agents used to involve manual invocation through channels like the Salesforce AgentForce chat model. Today, Invokable Agent Actions enable you to invoke any active AgentForce agent from Apex and flow.

These features enable some significant use cases, such as:

Invoking AgentForce Agents

Salesforce sales remains a place for low-code developers and pros, and Agentforce is no different. You can call AgentForce agents through Flow or without code from an Apex method. Either way, you will define an agent and call it with the user’s message and, optionally, a session ID.

Your message is an initiator, but what is an agent session ID, and how is it generated? The session ID creates a correlation for every interaction between a user and an agent. If a user sends his first message, one session ID is created. You will send this ID with further messages so the agent knows what has been discussed before and can keep context. Few use cases need multi-turn conversations, but where they do, you will have to employ session IDs.

Working with AI Agent Actions in Flows

You can call any active AgentForce agent in a flow via a regular AI agent action. To begin, build an action element and locate the AI ​​Agent Actions folder. There will be an action for every active AgentForce agent. Once you’ve chosen an agent, define the user message and optional session ID inputs.

As the best practice, you must generate input variables for the user message and the session ID for your flow dynamically. You must also add the output variable of an agent’s response to capture the agent’s response.

AI Agent Action-enabled flows are a compelling means of weaving agentic AI into your Salesforce organizations. You can invoke updates to records using fast action buttons and weave them into screen flows. You can also streamline minimal agent-to-agent communication by leveraging them in flow-based agent actions.

Use AI Agent Actions whenever you want to introduce rapid, agent-coordinated automation into Salesforce. Pay attention to the fact that all the same best practices for flow remain in effect. You will need to know the terms of flow and apply error handling.

Using Invocable Actions in Apex

The Invocable Actions API can be used to call your AgentForce agents in Apex.

First, define a custom generateAiAgentResponse action. In order to define an action, you will need to provide the agent API name, which can be located on the agent details page in Salesforce Setup.

Then, pass the necessary user message and optional session ID to the action as invocation parameters. Lastly, call the action.

Conclusion:

Agentforce agents transform the way companies engage with employees and customers alike by automating and simplifying processes inside and outside of Salesforce. With invocable agent actions, developers are now able to invoke agents from Apex and Flow, allowing for faster, smarter, and more connected experiences. Whether it’s initiating agentic flows from buttons and components, connecting outside systems through REST, or managing agent-to-agent communications, these features create limitless possibilities.

Contact Us
Loading
Your message has been sent. Thank you!
© Copyright iTechCloud Solution 2024. All Rights Reserved.