Retrieve Document Suggestions using Apex
Retrieve Document Suggestions using Apex
Prerequisite
Ensure that you have your Case Assist ID on hand.
Retrieving Document Suggestions
-
In Salesforce, access the Developer Console.
-
Instantiate the
CaseAssistApiClient
as follows:String caseAssistId = '00000000-0000-0000-0000-000000000000'; Boolean debug = false; CoveoV2.CaseAssistApiClient client = CoveoV2.CaseAssistApiClient.getClient(caseAssistId, debug);
NoteThe
debug
parameter is optional. It indicates whether to include an execution report for debugging purposes. The default value isfalse
. -
Invoke the
getDocumentSuggestions
method 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
getDocumentSuggestions
method takes aMap<String, Object>
as an input. -
Specify values for the following arguments:
-
numberOfResults
is an optional parameter that specifies the maximum number of results to return. The default value is5
.NoteThe
numberOfResults
parameter is available in Coveo for Salesforce v4.17 and later releases. -
clientID
identifies a specific instance of a browser client and provides insights into the events performed by the user. -
fields
represents the fields of the current case that are considered meaningful for providing relevant documents. Thesubject
anddescription
fields 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 avalue
key.
-
-
-
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.