Retrieve Document Suggestions using Apex
Retrieve Document Suggestions using Apex
|
|
Available since
This feature was introduced in the August 2020 release of Coveo for Salesforce version 4.7. |
Prerequisite
Ensure that you have your Case Assist ID on hand.
Retrieving Document Suggestions
-
In Salesforce, access the Developer Console.
-
Instantiate the
CaseAssistApiClientas follows:String caseAssistId = '00000000-0000-0000-0000-000000000000'; Boolean debug = false; CoveoV2.CaseAssistApiClient client = CoveoV2.CaseAssistApiClient.getClient(caseAssistId, debug);NoteThe
debugparameter is optional. It indicates whether to include an execution report for debugging purposes. The default value isfalse. -
Invoke the
getDocumentSuggestionsmethod to retrieve the document suggestions.ExampleInteger numberOfResults = 5; Map<String, Object> result = client.getDocumentSuggestions(new Map<String, Object> { 'clientId' => '04850f2-ee0d-47a9-aff5-39ee47f294f9', 'fields' => new Map<String, Object> { 'subject' => new Map<String, Object> { 'value' => 'My Case Subject' }, 'description' => new Map<String, Object> { 'value' => 'My Case Description' } }, 'context' => new Map<String, Object> { 'key' => 'value' } }, numberOfResults);The
getDocumentSuggestionsmethod takes aMap<String, Object>as an input. -
Specify values for the following arguments:
-
numberOfResultsis an optional parameter that specifies the maximum number of results to return. The default value is5.NoteThe
numberOfResultsparameter is available in Coveo for Salesforce v4.17 and later releases. -
clientIDidentifies a specific instance of a browser client and provides insights into the events performed by the user. -
fieldsrepresents the fields of the current case that are considered meaningful for providing relevant documents. Thesubjectanddescriptionfields are typically used to retrieve matching documents.Notes-
More fields can be added to better suit your use case.
-
The field values should be read from the current case and passed as a
Map<String, Object>with avaluekey.
-
-
-
Optionally, provide context information to leverage in the query pipeline (see Manage ranking expression rules and Manage query pipeline conditions).
The result is a
Map<String, Object>, which contains a list of document suggestions.ExampleList<Object> documents = (List<Object>)result.get('documents');You can now retrieve and use document suggestions in your own application.