Retrieving Document Suggestions using Apex

Prerequisite

Ensure that you have your Case Assist ID on hand.

Retrieving Document Suggestions

  1. In Salesforce, access the Developer Console.

  2. Instantiate the CaseAssistApiClient as follows:

    String caseAssistId = '00000000-0000-0000-0000-000000000000';
    Boolean debug = false;
    CoveoV2.CaseAssistApiClient client = CoveoV2.CaseAssistApiClient.getClient(caseAssistId, debug);
    Note

    The debug parameter is optional. It indicates whether to include an execution report for debugging purposes. The default value is false.

  3. Invoke the getDocumentSuggestions method to retrieve the document suggestions.

    Example
    Integer 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 a Map<String, Object> as an input.

  4. Specify values for the following arguments:

    1. numberOfResults is an optional parameter that specifies the maximum number of results to return. The default value is 5.

      Note

      The numberOfResults parameter is available in Coveo for Salesforce v4.17 and later releases.

    2. clientID identifies a specific instance of a browser client and provides insights into the events performed by the user.

    3. fields represents the fields of the current case that are considered meaningful for providing relevant documents. The subject and description 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 a value key.

  5. 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.

    Example
    List<Object> documents = (List<Object>)result.get('documents');

    You can now retrieve and use document suggestions in your own application.