Loading
Upcoming Mandatory Changes to Public Key Infrastructure (PKI)Read More
Salesforce Enforces New Security Requirements in Summer 2026Read More
Visual Studio Code Based Modeler for Consumer Goods Cloud
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Set Agent Context

          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 setAgentContextAsync to initialize the client.
          • If you call setAgentContextAsync before you initialize the agent, the API returns a NoAgentforceSessionClient error 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 setAgentContextAsync to 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.
           
          Loading
          Salesforce Help | Article