Contact Us

March 28, 2025

June 25, 2026 1:02 am

Invoking Custom LWC in Agentforce with CLT

Share with

Understanding the Issue

CLT prefers Apex text responses by default. When you call an Apex action from a Service Agent, the agent executes the Apex, directly renders whatever the Apex returns (String / text), and stops there. If Apex returns a String, CLT treats it as the final answer and will not invoke your LWC automatically.

The root cause of this issue is the Apex return type and the Agent Action output configuration. If the Apex returns a String, CLT will only display the text and will not invoke the LWC. The LWC is only rendered when the Agent Action output is set to a UI component or via Screen Flow.

Configuring CLT to Invoke LWC

To invoke the LWC, you need to configure the Agent Action to return structured data and map it to an Output UI component. The Apex must return a Map or a wrapper class (not a String). Alternatively, you can use Screen Flow to render the LWC.

ApexExample.cls

@AuraEnabled
public static Map getData() {
    return new Map{
        'status' => 'success',
        'amount' => 5000
    };
}

Another option is to use Screen Flow to render the LWC. This approach is more reliable and allows for more complex UI rendering.

Best Practices

The correct architecture for invoking an LWC in Agentforce with CLT is:

  • Service Agent
  • Agent Action
  • Apex (returns structured data)
  • Flow / Agent UI Output
  • Custom LWC (renders UI)

Heads up: CLT cannot auto-launch an LWC just because Apex ran. Returning text equals a final answer, and Apex → LWC direct chaining is not supported.

Checklist

  • Apex return type is not String
  • Action output type is UI / Component
  • LWC is registered for Agent / Flow
  • Using Screen Flow if UI is needed
  • Agent Action is configured to return structured data
  • Apex returns a Map or a wrapper class

Frequently Asked Questions

What is the difference between Text Response and UI Response in CLT?

Text Response is used when the Apex action returns a String, and CLT renders it directly as the final response. UI Response is used when the Apex action returns structured data, and CLT invokes the LWC to render the UI.

Can I use Screen Flow to render the LWC?

Yes, you can use Screen Flow to render the LWC. This approach is more reliable and allows for more complex UI rendering.

What is the correct architecture for invoking an LWC in Agentforce with CLT?

The correct architecture is: Service Agent → Agent Action → Apex (returns structured data) → Flow / Agent UI Output → Custom LWC (renders UI).

Why is my LWC not being invoked?

Your LWC may not be invoked if the Apex return type is String, or if the Agent Action output is not configured to use a UI component or Screen Flow.

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