Add custom context to the Hosted Insight Panel

In this article

To add custom context to the Hosted Insight Panel, you must create a custom Apex class that implements the CoveoV2.HostedCustomContextInterface as described in this article.

To add custom context

  1. Create an Apex class that implements the CoveoV2.HostedCustomContextInterface as follows:

    Example
    global class MyCustomContext implements CoveoV2.HostedCustomContextInterface {
      public Map<String, Object> getCustomContext(Map<String, Object> data) {
        // Retrieves the record ID that's currently being accessed in the Hosted Insight Panel.
        String currentRecordId = (String)data.get('recordId');
        // Returns the map of custom context values that will be added to each query.
        return new Map<String, Object>{'key1' => 'value1', 'recordId' => currentRecordId, 'listOfValues' => new List<String>{'listValue1', 'listValue2'}};
      }
    }

    Where:

    • key1 is the context key/value pair to add to each query.

    • recordId is the ID of the record that’s currently being accessed in the Hosted Insight Panel.

    • listOfValues is the array of context values to add to each query.

  2. Save the Apex class.

What’s next?

Once you’ve created an Apex class that implements the CoveoV2.HostedCustomContextInterface, you’ll be able to select it from the Custom Context Provider picklist in the Coveo Hosted Insight Panel component to augment queries with the additional context returned by your custom Apex class.