--- title: Globals Class slug: '1075' canonical_url: https://docs.coveo.com/en/1075/ collection: coveo-for-salesforce source_format: adoc --- # Globals Class The `Globals` class allows external Apex code to access some Coveo for Salesforce features. ## generatePlatformToken Generates a platform token that can be used to invoke any Coveo API except the [Search API](https://docs.coveo.com/en/13/). Under the hood, this function calls the Coveo Platform API [`+/rest/organizations/{organizationId}/tokens+`](https://platform.cloud.coveo.com/docs?urls.primaryName=AuthorizationServer#/Platform%20Tokens) endpoint. ```apex String token = CoveoV2.Globals.generatePlatformToken(); ``` Where the `` (Object, Optional) parameter lets you pass additional content and request the [privileges](https://docs.coveo.com/en/228/) necessary for the services you will be invoking with the platform token. The following example shows an Apex implementation of the API call to generate a platform token with the corresponding options. For more information, see the [Platform Tokens Swagger documentation](https://platform.cloud.coveo.com/docs?urls.primaryName=AuthorizationServer#/Platform%20Tokens/rest_organizations_paramId_tokens_post). **Example** ```apex CoveoV2.PlatformToken.SearchTokenOptions searchOptions = new CoveoV2.PlatformToken.SearchTokenOptions(); searchOptions.userIds.add(new CoveoV2.UserIdentity('myAdditionalIdentity')); Map tokenOptions = new Map { 'search' => searchOptions, 'privileges' => new List { new CoveoV2.PlatformToken.TokenPrivilege('CUSTOMER_SERVICE', 'USE_CASE_ASSIST', 'ENABLE'), new CoveoV2.PlatformToken.TokenPrivilege('USAGE_ANALYTICS', 'ANALYTICS_DATA ', 'EDIT') } }; String myToken = CoveoV2.Globals.generatePlatformToken(tokenOptions); ``` ## generateSearchToken Generates a search token that can then be used to invoke the Coveo Search REST API in Coveo. Under the hood, this calls the [Coveo Search API `/rest/search/v2/token` endpoint](https://docs.coveo.com/en/56#request-a-search-token). ```apex String token = CoveoV2.Globals.generateSearchToken(); ``` Where the `` (Object, Optional) parameter allows you to pass additional information that should be added to the search token. **Example:** ```apex String token = CoveoV2.Globals.generateSearchToken(new Map { 'filter' => '@source==KnowledgeBase', 'pipeline' => 'InternalSearch' }); ``` ### additionalUserIdentity (Optional) Specifies a list of [identities to add to the token](https://docs.coveo.com/en/56#userids-array-of-restuserid-required). For example, this can be used when you have a specific identity that has access to documents that everyone should be able to see. **Example:** ```apex String token = CoveoV2.Globals.generateSearchToken(new Map { 'additionalUserIdentities' => new List{ 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 uses the following constructor: ```apex UserIdentity(, , ) ``` Where: * ``: (String, Required) The identity provider to add. * ``: (String, Optional) The security provider of your user identity. * ``: (String, Optional) The virtual group your identity belongs to. > **Note** > > For more information on user identities, see [Coveo management of security identities and item permissions](https://docs.coveo.com/en/1719/). ### filter (Optional) The filter query expression to apply when authenticating a query with this search token. This expression will be merged with the constant part of the query expression (`cq`) using an `AND` operator. The filter can also be used in query pipeline condition statements (for example,`when $constantQuery contains \"@source==KnowledgeBase\"`). **Example:** `@source==KnowledgeBase` ```apex String token = CoveoV2.Globals.generateSearchToken(new Map { 'filter' => '@source==KnowledgeBase' }); ``` ### pipeline (Optional) The name of the query pipeline to use when authenticating a query with this search token. This query pipeline will take precedence over the possible output of all other query pipeline routing mechanisms when using this search token (see [Query Pipeline Routing Mechanisms and Rules](https://docs.coveo.com/en/1666/)). **Example:** `InternalSearch` ```apex String token = CoveoV2.Globals.generateSearchToken(new Map { 'pipeline' => 'InternalSearch' }); ``` ### searchHub (Optional) The name of the search hub to enforce when authenticating a query with this search token. This value will override the `searchhub` parameter of the query itself, and will be passed as the `originLevel1` property value when logging usage analytics search events. The search hub can also be used in query pipeline condition statements (for example, `when $searchhub is \"CommunityHub\"`). **Example:** `SupportHub` ```apex String token = CoveoV2.Globals.generateSearchToken(new Map { 'searchHub' => 'SupportHub' }); ``` ### userDisplayName (Optional) The `userDisplayName` to pass when logging usage analytics search events. This information is leveraged in the **Analytics** section of the Coveo Administration Console. **Example:** `Alice Smith` ```apex String token = CoveoV2.Globals.generateSearchToken(new Map { 'userDisplayName' => 'Alice Smith' }); ``` ### userGroups (Optional) The `userGroups` to pass when logging usage analytics search events. This information is leveraged in the **Analytics** section of the Coveo Administration Console. User groups can be also be used in query pipeline condition statements (for example, `when $groups contains \"Employees\"`). **Example:** `["Tech support agents", "Employees"]` By default, the service uses the user profile name inside Salesforce. ```apex String token = CoveoV2.Globals.generateSearchToken(new Map { 'userGroups' => new List{ "Tech support agents","Employees" } }); ``` ### validFor (Optional) The number of milliseconds the search token will remain valid for once it has been created. **Minimum value:** `900000` (that is, 15 minutes) **Maximum/default:** `86400000` (that is, 24 hours) ```apex String token = CoveoV2.Globals.generateSearchToken(new Map { 'validFor' => '3600000' }); ```