You are here:
Set Agent Context
Updates the context of an active Agentforce session dynamically as users move between screens, such as, from an Account detail page to Visits or Orders.
Required Editions
| Available in: Enterprise and Unlimited Editions where Consumer Goods Cloud is enabled |
Parameters
payload: A JSON parameter containing the new context data.
Returns
It returns a success result if the context is successfully updated, or a failure result containing specific error codes.
Usage Considerations
To use this API, update UI and Process contracts to pass the accurate context during navigation. Make sure these guidelines are met:
Sample GET requests:
- You must launch the Agentforce sidebar at least once before calling
setAgentContextAsyncto initialize the client. - If you call
setAgentContextAsyncbefore you initialize the agent, the API returns aNoAgentforceSessionClienterror and the context does not update. If you launch the agent after this, it will use the previous or default context from the launch command. - After initialization, use
setAgentContextAsyncto update the context. This works even when the sidebar window is collapsed.
Error Handling
When the asynchronous operation fails, it returns one of these error codes:
| Error Code | Description |
|---|---|
InvalidContextJSON |
The payload passed to the function is invalid or cannot be parsed into a correct page context object. |
AgentforceSidebarNotEnabled |
This function was called on a phone, which is not supported, or when the sidebar feature is turned off. |
NoAgentforceSessionClient |
This function is called before Agentforce is launched for the first time. |
AgentforceAdditionalContextError |
The additional context or variables passed in the payload failed to be set because the SDK returned the error. |
Did this article solve your issue?
Let us know so we can improve!

