You are here:
Custom Lightning Web Components in the Agentforce Chat Window
Show custom Lightning Web Components as agent action responses in the Agentforce chat window on the Life Sciences Cloud mobile app. On the mobile app, components receive parameters differently than on the desktop site, so your LWC code must handle both patterns.
Required Editions
| Available in: Lightning Experience |
| Available in: Enterprise and Unlimited Editions with Life Sciences Cloud, Life Sciences Cloud for Customer Engagement Add-on license, and the Life Sciences Customer Engagement managed package. |
The Life Sciences Cloud mobile app supports rendering custom LWCs in the Agentforce chat
window. To configure the custom Lightning type bundle for mobile, including the
lightningMobileGenAi channel directory and required form factors, see Custom Lightning Types in the Salesforce Mobile App. For a full
example of creating a custom Lightning type bundle, see Example: Create Custom UI with an Editor and Renderer Override.
LWC Metadata Requirements for Mobile
To support the Agentforce chat window on the mobile app, make sure your LWC
js-meta.xml file includes both of the following targets:
lightning__AgentforceOutputlightning__UrlAddressable— required for Lightning Mobile Runtime navigation
In the targetConfig for lightning__AgentforceOutput,
include supported form factors for both desktop and mobile:
<supportedFormFactors>
<supportedFormFactor type="Large"/>
<supportedFormFactor type="Small"/>
</supportedFormFactors>How Parameters Are Passed on the Mobile App
On the desktop site, Agentforce passes Apex class attributes to the LWC through an
@api value getter and setter. Parameter names match the Apex class
attributes directly.
On the Life Sciences Cloud mobile app, the component loads through Lightning Mobile Runtime
by using page reference navigation. Parameters arrive through the
CurrentPageReference wire adapter in the page reference state object.
The mobile app prefixes each parameter name with c__. For example, an
Apex attribute named metrics arrives as c__metrics. See PageReference Types.
The mobile app also passes a c__channel parameter with a value of
Mobile. Use this value to determine which parameter-passing pattern to
apply when you build a component that works on both the desktop site and the mobile
app.
Example: Handle Both Desktop and Mobile Parameters
This example shows how a single component handles parameters from the desktop site and the mobile app.
import { LightningElement, api, wire } from 'lwc';
import { CurrentPageReference } from 'lightning/navigation';
export default class MyAgentComponent extends LightningElement {
_value;
// Desktop
@api
get value() {
return this._value;
}
set value(newValue) {
if (!newValue) { return; }
this._value = newValue;
this.processData();
}
// Mobile
@wire(CurrentPageReference)
handlePageReference(pageRef) {
if (!pageRef?.state) { return; }
if (pageRef.state.c__channel === 'Mobile') {
this._value = pageRef.state.c__metrics;
this.processData();
}
}
processData() {
// Parse and render the data
}
}- Activate the Custom Lightning Type for Agentforce Mobile
After you deploy your custom Lightning type bundle and Lightning Web Components (LWC), update the agent action to use the custom type. This update makes sure that the component renders in the Agentforce chat window on the mobile app.
