Set Up Context Passing for Agentforce
Help your agents work faster and with greater accuracy by analyzing contextual data in the Consumer Goods Cloud mobile app. You can define how the app builds and sends this context by setting up process and business logic contracts in your customization project.
Required Editions
| Available in: Enterprise and Unlimited Editions that have Consumer Goods Cloud enabled |
| User Permissions Needed | |
|---|---|
| To configure context passing for Agentforce | Developer, Customizer |
Note Context passing works when you use Agentforce in the Consumer Goods Cloud
mobile app on a physical mobile device. It doesn't work in the Modeler simulator app.
For example, to pass the visit ID from the store cockpit, perform these steps:
- Open your customization project in Visual Studio Code based Modeler.
-
If needed, define an
Actionlogic in a process contract.- Open the relevant process contract.
-
Implement a logic to pass data to
Actionor fetch data from an already available object. In this example, create a logicActionthat uses the object name and record ID as input parameters to call the custom business logic.<Action actionType="LOGIC" name="LaunchAgentforce" call="ProcessContext::CardController.launchAgentforce"> <Parameters> <Input name="objectName" type="Literal" value="Visit" /> <Input name="recordId" type="Binding" value="ProcessContext::mainBO.PKey" /> </Parameters> </Action> -
Add the
agentforceLaunchEventexternal event and bind it to the action.<ExternalEvent name="agentforceLaunchEvent" action="LaunchAgentforce" />
Here’s a sample of the process contract configuration:
<!-- Define the Action to call the Business Logic function --> <Action actionType="LOGIC" name="LaunchAgentforce" call="ProcessContext::CardController.launchAgentforce"> <Parameters> <!-- Pass the Object API Name --> <Input name="objectName" type="Literal" value="Visit" /> <!-- Pass the Record ID dynamically from the current Business Object --> <Input name="recordId" type="Binding" value="ProcessContext::mainBO.PKey" /> </Parameters> </Action> <!-- Define the External Event to intercept the header button click --> <ExternalEvent name="agentforceLaunchEvent" action="LaunchAgentforce" /> -
Implement the logic to construct the payload and call the native facade.
- Open the business logic contract referenced in your process action.
-
Implement the function matching the name defined in your
Actioncall. -
Construct the JSON payload containing the
objectApiNameand attributes. -
Invoke the
Facade.launchAgentForce()function.
Here’s a sample of the business logic implementation:
function launchAgentforce(objectName, recordId){ var me = this; ////////////////////////////////////////////////////////////////////////////// // Add your customizing javaScript code below. // ////////////////////////////////////////////////////////////////////////////// var promise; let payload = { "objectAPIName": objectName, "attributes": { "recordId": recordId } }; Facade.launchAgentForce(payload); promise = Promise.resolve(); ////////////////////////////////////////////////////////////////////////////// // Add your customizing javaScript code above. // ////////////////////////////////////////////////////////////////////////////// return promise; }
Sample payload structure for a specific visit record that is marked as urgent.
{
"objectApiName": "Visit",
"attributes": {
"recordId": "a00xx0000012345AAA",
"pageType": "standard_recordPage",
"actionName": "view"
},
"additionalAttributes": [
{
"name": "customStatus",
"value": "urgent",
"type": "String"
}
]
}Parameter Details:
objectApiName: (String) Required. The API name of the Salesforce object context.attributes: (Object) Required. A container for record identifiers, specifically recordId.additionalAttributes: (Array) Optional. Key-value pairs for extra context.
Did this article solve your issue?
Let us know so we can improve!

