---
schema_version: "1"
id: 3035180b2855ff4f1f9f230aa2d85190acd7efca8282247cd753e38402de19d1
title: TokenUtility Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_class_pref_center_TokenUtility.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_pref_center_TokenUtility.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 0d37a57bc6ceb516411acc064ef4808a094dfae6a4cb0d720f45bb513c3cf163
description: Generate authentication tokens to access preference forms.Returns the authentication token for the specified token value using the given token type.Returns the authentication token for the specified token value using the default standard token type.Returns the authentication tokens in the form of a map, where the map key is the input value to be tokenized and the map value is the corresponding token. The given token type is used to generate the tokens.Returns the generated tokens in the form of a map. This method uses the default standard token type to generate the tokens.
---
# TokenUtility Class

Generate authentication tokens to access preference forms.

## Namespace

[Pref\_center](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_pref_center.htm "The Pref_center namespace provides an interface, classes, and methods to create and retrieve data in forms in Preference Manager. Preference Manager, previously called Preference Center, is a feature within the Privacy Center app.")

## Example

Call the generateToken() method to generate a single token for a specified Salesforce record ID:

Individual individual = \[SELECT Id FROM Individual WITH USER\_MODE LIMIT 1\];
String token = pref\_center.TokenUtility.generateToken(individual.Id);
// Do something with the token
System.debug(token);

Call the generateTokens() method to generate tokens in bulk when given a list of Salesforce record IDs:

List<Id> individualIds = new List<Id>();
// Get Ids of Individuals who have not opted out of tracking
for (Individual individual : \[SELECT Id FROM Individual WHERE HasOptedOutTracking = false WITH USER\_MODE\]) {
    individualIds.add(individual.Id);    
}
// Generate tokens for the list of Individual record Ids
Map<String, String\> tokens = pref\_center.TokenUtility.generateTokens(individualIds);
String firstIndividualId = individualIds\[0\];
// The returned Map has the input record Id as key and the corresponding token as value
String tokenForFirstIndividual = tokens.get(firstIndividualId);
// Do something with the token
System.debug(tokenForFirstIndividual);

- **[TokenUtility Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_pref_center_TokenUtility.htm#apex_pref_center_TokenUtility_methods)**

## TokenUtility Methods

The following are methods for TokenUtility.

- **[generateToken(tokenValue, tokenType)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_pref_center_TokenUtility.htm#apex_pref_center_TokenUtility_generateToken)**  
    Returns the authentication token for the specified token value using the given token type.
- **[generateToken(tokenValue)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_pref_center_TokenUtility.htm#apex_pref_center_TokenUtility_generateToken_2)**  
    Returns the authentication token for the specified token value using the default standard token type.
- **[generateTokens(tokenValues, tokenType)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_pref_center_TokenUtility.htm#apex_pref_center_TokenUtility_generateTokens)**  
    Returns the authentication tokens in the form of a map, where the map key is the input value to be tokenized and the map value is the corresponding token. The given token type is used to generate the tokens.
- **[generateTokens(tokenValues)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_pref_center_TokenUtility.htm#apex_pref_center_TokenUtility_generateTokens_2)**  
    Returns the generated tokens in the form of a map. This method uses the default standard token type to generate the tokens.

### generateToken(tokenValue, tokenType)

Returns the authentication token for the specified token value using the given token type.

#### Signature

public static String generateToken(String tokenValue, pref\_center.TokenType tokenType)

#### Parameters

- **tokenValue**: Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.") The value passed to LoadParameters.getRecordId() and SubmitParameters.getRecordId(). Identifies the entity that the preference form is acting on.
- **tokenType**: Type: [pref\_center.TokenType](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_enum_pref_center_TokenType.htm "Defines the types of values supported by the TokenUtility methods.") Specifies the type of the value to be encrypted with authentication tokens.

#### Return Value

Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")

### generateToken(tokenValue)

Returns the authentication token for the specified token value using the default standard token type.

#### Signature

public static String generateToken(String tokenValue)

#### Parameters

- **tokenValue**: Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.") Identifies the entity that the preference form is acting on. The value passed to LoadParameters.getRecordId() and SubmitParameters.getRecordId().

#### Return Value

Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")

### generateTokens(tokenValues, tokenType)

Returns the authentication tokens in the form of a map, where the map key is the input value to be tokenized and the map value is the corresponding token. The given token type is used to generate the tokens.

#### Signature

public static Map<String,String\> generateTokens(List<String\> tokenValues, pref\_center.TokenType tokenType)

#### Parameters

- **tokenValues**: Type: List<[String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")\> The values passed to LoadParameters.getRecordId() and SubmitParameters.getRecordId(). Identifies the entity that the preference form is acting on. Contains multiple values to be encrypted with authentication tokens.
- **tokenType**: Type: [pref\_center.TokenType](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_enum_pref_center_TokenType.htm "Defines the types of values supported by the TokenUtility methods.") Specifies the type of the value to be encrypted with authentication tokens.

#### Return Value

Type: Map<[String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type."),[String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")\>

### generateTokens(tokenValues)

Returns the generated tokens in the form of a map. This method uses the default standard token type to generate the tokens.

#### Signature

public static Map<String,String\> generateTokens(List<String\> tokenValues)

#### Parameters

- **tokenValues**: Type: [List](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_list.htm#apex_methods_system_list "Contains methods for the List collection type.")<[String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")\> The list of string values passed to LoadParameters.getRecordId() and SubmitParameters.getRecordId(). Contains multiple values to be encrypted with authentication tokens.

#### Return Value

Type: [Map](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_map.htm#apex_methods_system_map "Contains methods for the Map collection type.")<[String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type."),[String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")\>, where the map key is the input value to be tokenized and the map value is the corresponding token.