Add custom context to the Hosted Insight Panel
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
-
Create an Apex class that implements the
CoveoV2.HostedCustomContextInterface
as follows:Exampleglobal 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:
-
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.