Globals Class

The Globals class allows external Apex code to access some of the Coveo for Salesforce features.

generateSearchToken

Generates a search token that can then be used to invoke the Coveo Search REST API on the Coveo Cloud platform.

String token = CoveoV2.Globals.generateSearchToken();

The params parameter allows you to pass additional information that should be added to the search token.

filter

(Optional) Specifies a query filter to be included in all queries performed using this token.

This can be used to effectively restrict the items available through the generated search token.

String token = CoveoV2.Globals.generateSearchToken(new Map<String, Object> {
    'filter' => '@objecttype'
});

searchHub

(Optional) Specifies the name of the search hub to use when logging events in the Coveo Analytics. For example, this can be used to ensure that only queries recorded from a specific hub are provided with auto-completion.

String token = CoveoV2.Globals.generateSearchToken(new Map<String, Object> {
    'searchHub' => 'mySearchHub'
});

userGroups

(Optional) Specifies an array of user groups to use when logging events in the Coveo Analytics using this token. By default, it uses the user profile name inside Salesforce.

String token = CoveoV2.Globals.generateSearchToken(new Map<String, Object> {
    'userGroups' => new List<String>{'a','b'}
});

additionalUserIdentity

(Optional) Specifies a list of identities to add to the token. For example, this can be used when you have a specific identity that has access to documents that everyone should be able to see.

String token = CoveoV2.Globals.generateSearchToken(new Map<String, Object> {
    'additionalUserIdentities' => new List<CoveoV2.UserIdentity>{
        new CoveoV2.UserIdentity('john@doe.com'),
        new CoveoV2.UserIdentity('jane@doe.com','Email Security Provider')
        new CoveoV2.UserIdentity('jane@doe.com','Email Security Provider','USER')
    }
});

The UserIdentity class used to add user identities use the following constructor:

UserIdentity(String name, String provider, String type)
  • name: the identity provider to add.
  • provider: (optional) the security provider of your user identity.
  • type: (optional) the virtual group your identity belongs to.

For more information on user identities, see Coveo Cloud V2 Management of Security Identities and Item Permissions.

This REST API is available at:

  • Coveo Cloud V1: ‘https://cloudplatform.coveo.com/rest/search’
  • Coveo Cloud V2: ‘https://platform.cloud.coveo.com/rest/search’

For more information, see REST Search API Home.