Loading
Agentforce and Einstein Generative AI
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Call an Agent from a Flow or Apex Class

          Call an Agent from a Flow or Apex Class

          Give your users access to your agent’s subagents, actions, and reasoning capabilities to automate repetitive tasks and provide real-time assistance. Use invocable actions to call an Agentforce Service agent, Agentforce Employee agent, or Agentforce (Default) from a flow or Apex class. You can call an agent to complete background or event-driven tasks from anywhere that you can invoke a flow or Apex class.

          Required Editions

          Available in: Lightning Experience
          Available in: Enterprise, Performance, Unlimited, and Developer Editions. Required add-on licenses vary by agent type.
          Important
          Important Starting June 17, 2025, Agentforce (Default) will not include new features or improvements and isn’t available in new Salesforce environments. We recommend migrating to Agentforce Employee agent for continued enhancements and support. If you plan to transition to Agentforce Employee agent or make related license changes, complete the migration of your existing Agentforce (Default) agents in advance to avoid potential disruption in agent availability. If you can't complete the migration in advance, you can create new agents after the transition, which can involve some downtime. See Migrate from Agentforce (Default) to Agentforce Employee Agent.

          Salesforce provides custom and standard invocable actions for calling an agent from a flow or Apex class.

          Custom Agent Invocable Actions

          Custom agent invocable actions handle more of the conversation automatically, and we recommend them for most use cases. Salesforce provides a custom agent invocable action for each Agentforce Service agent, Agentforce Employee agent, and Agentforce (Default) in your org.

          Custom agent invocable actions make it easy to configure your agent’s behavior with clicks, not code. For example, when you add a custom agent invocable action to an Apex class or flow, you use a UI to specify the conditions that trigger the agent, the task to complete, and the data needed to complete the task. You define the task for the agent to complete by specifying a user message. The agent uses it to select subagents and actions, just like if a user had asked a question or made a request in a chat window. You can also define the fields that you want your agent to respond with, and then use those field values in your flow or Apex class.

          Consider adding multiple custom agent invocable actions to a flow or Apex class depending on your use case. For example, you can call an agent to summarize a service case and then make a second call to use that summary to draft an email response. You can call the same agent multiple times from the same flow to handle separate but related tasks. Or you can call multiple agents from the same flow to handle more specialized tasks.

          Standard Agent API Invocable Actions

          Standard Agent API invocable actions give you direct access to the Agent API from a flow or Apex class. They provide more granular control over the agent’s behavior during a session than custom agent invocable actions, but they require additional configuration. We recommend them for advanced use cases only.

          For example, use the End Session action to make sure a session ends when certain conditions are met. Or use the Submit Feedback action to collect user feedback on the conversation and store it in Data Cloud.

          Salesforce provides the following standard Agent API actions.

          • End Session
          • Send Message
          • Start Session
          • Submit Feedback
          Learn more about Agent API actions in Agent API Flow Core Actions.

          Custom agent invocable actions and standard agent API invocable actions aren't supported for Experience Cloud site users and Platform Integration User. The Platform Integration User is also referred to as the System User or system context.

          Flows that call an Agentforce Service agent run in the context of the agent user. Flows that call an Agentforce Employee agent or Agentforce (Default) run in the context of the authenticated end user.

          In flows, you can only call custom agent invocable actions and standard agent API invocable actions in asynchronous paths, not in a paths that run immediately.

          Prepare to Call an Agent from an Apex Class or Flow

          Create an Agentforce Service agent, Agentforce Employee agent, or Agentforce (Default).

          Prepare your agent’s subagents and actions. Because standard subagents and actions are designed for conversational use cases, they may not work as expected with agent invocable actions. Consider removing standard subagents and actions from your agent and creating custom actions for your use cases.

          Custom agent invocable actions don't support custom variables or these standard context variables: $Context.EndUserId, $Context.RoutableId, $Context.EndUserLanguage, and $Context.EndUserContactId.

          If you’re using an Agentforce Service agent, make sure that your agent has the necessary access to any records used by your agent actions. For example, if you want your agent to be able to summarize a case, create a permission set and modify the object settings to grant read access for the Case object. Then assign the permission set to the agent user.

           
          Loading
          Salesforce Help | Article