Contact Us

May 22, 2024

May 15, 2026 8:51 am

Invoking Agentforce Agents from Record-Triggered Flows in Salesforce

Share with

Understanding the Issue

The error message suggests that the chat-window substrate is not available in the trigger execution context, which is expected since the chat window is a UI component. The supported pattern is to invoke the agent via Apex, using the Invocable.Action.createCustomAction method.

The standard AI Agent Flow Action is not designed to work in trigger execution contexts, as it relies on the chat-window substrate, which is not available in these contexts.

Using the Apex API

To invoke the Agentforce agent from a Record-Triggered Flow, you can use the Apex API to create a custom action that generates the AI agent response. This approach bypasses the standard AI Agent Flow Action and allows you to invoke the agent in a UI-less context.

AgentforceApexInvoker.cls

public class AgentforceApexInvoker {    public static void invokeAgent(String prompt) {        // Create a custom action to generate the AI agent response        Invocable.Action action = new Invocable.Action('generateAiAgentResponse');        // Set the prompt and other parameters        action.setParameters(new Map {'prompt' => prompt});        // Invoke the action and get the response        Object response = action.invoke();        // Parse the response and create records in the custom object        // ...    }}

Best Practices

When invoking Agentforce agents from Record-Triggered Flows, make sure to follow these best practices:

Checklist

  • Use the Apex API to invoke the Agentforce agent, bypassing the standard AI Agent Flow Action.
  • Make sure the agent is configured to return a JSON response only.
  • Use an autolaunched subflow to invoke the agent and parse the response.
  • Set the flows to System Context Without Sharing to avoid permission issues.
  • Confirm that the running user has the Agentforce User permission set and System Admin profile.
  • Check the Trust status and related known issues before invoking the agent.

Frequently Asked Questions

What is the difference between the standard AI Agent Flow Action and the Apex API?

The standard AI Agent Flow Action is designed to work in UI contexts, while the Apex API is designed to work in UI-less contexts, such as Record-Triggered Flows.

Can I use the chat window with the Apex API?

No, the chat window is not available in UI-less contexts, such as Record-Triggered Flows.

How do I parse the JSON response from the Agentforce agent?

You can use an Apex class to parse the JSON response and create records in the custom object.

What are the benefits of using the Apex API to invoke the Agentforce agent?

The Apex API allows you to invoke the Agentforce agent in a UI-less context, such as a Record-Triggered Flow, and provides more flexibility and control over the invocation process.

Genetrix Technology · Salesforce Marketing Cloud Partner

Need help shipping this in production?

Genetrix builds and untangles Salesforce Marketing Cloud and Agentforce setups for teams that want it done right the first time. If anything in this post sounds familiar, talk to us before it ships.

Get in Touch with Genetrix →

Blogs for the

Business-Savvy!​

Let’s Connect

A 30 min no cost strategy session
with cloud support expert

Let’s Connect

A 30 min no cost strategy session
with cloud support expert