---
schema_version: "1"
id: 9d4ab0346f73d01480a32fabce522441debd7850a46e9062b9654dea78419706
title: Work with UserMappingService
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/salesforce-slack-sdk/apex-slack-sdk/guides/apex_ref/apex_ref_usermapping_service.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/guide/apex_ref_usermapping_service.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 83fcad0243661c8c322e3c4b31e72a4489f71c3656ec8eb752c0ef531813eba9
products:
  - Apex SDK for Slack (Beta)
---
# Work with UserMappingService

Use the `UserMappingService` class to query for existing [user mappings](https://help.salesforce.com/s/articleView?id=slack.slack_apps_digital_hq_shared_mapping.htm&type=5) stored in Salesforce. A Slack user mapping is created when a user links their Salesforce and Slack accounts in these ways.

- A [Salesforce connection](https://slack.com/help/articles/30754346665747-Connect-Salesforce-and-Slack#connect-slack-to-salesforce) is established in Slack and a user’s accounts are mapped, either automatically or manually.
- A Slack user authenticates a [Salesforce app](https://help.salesforce.com/s/articleView?id=slack.slack_apps_options.htm&type=5) by using their Salesforce account.
- An admin uses the [Mass User Provisioning API](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/orgs-mass-user.md) to link Salesforce and Slack accounts.

A user may have more than one mapping if they connect several Slack accounts to a Salesforce account.

## UserMappingService Class

**Usage**

```java
// UserMappingService.getSalesforceUserId
String salesforceUserId = Slack.UserMappingService.getSalesforceUserId('U000000001');
System.assertEquals('005xx000001X7yjAAC', salesforceUserId);

// UserMappingService.getSalesforceUserIdMap
List<String> slackIds = new List<String> {'U000000001', 'U000100002', 'U000100003'};
Map<String,String> resultMap = Slack.UserMappingService.getSalesforceUserIdMap(slackIds);
System.assertEquals(3, resultMap.size());
System.assertEquals('005xx000001X7yjAAC', resultMap.get('U000000001'));
System.assertEquals('005xx000001X7ykAAC', resultMap.get('U000100002'));

// UserMappingService.getSlackUserId
String teamId = 'T020L1EJEG3';
String slackId = Slack.UserMappingService.getSlackUserId('005xx000001X7yjAAC', teamId);
System.assertEquals('U000000001', slackId);

// UserMappingService.getSlackUserIdMap
String teamId = 'T020L1EJEG3';
List<String> salesforceIds = new List<String> {'005xx000001X7yjAAC', '005xx000001X7ykAAC', '005xx000001X7ylAAC'};
Map<String,String> resultMap = Slack.UserMappingService.getSlackUserIdMap(salesforceIds, teamId);
System.assertEquals(3, resultMap.size());
System.assertEquals('U000000001', resultMap.get('005xx000001X7yjAAC'));
System.assertEquals('U000100002', resultMap.get('005xx000001X7ykAAC'));
```

### UserMappingService Methods

The following are methods for `UserMappingService`.

#### getSalesforceUserId()

For a given Slack user ID, get the associated Salesforce user ID.

**Signature**

```java
public String getSalesforceUserId(String slackUserId)
```

**Parameters**

_slackUserId_

Type: String

**Return Value**

Type: String

#### getSalesforceUserIdMap()

Given a list of Slack user IDs, get the associated Salesforce user IDs. If at least one successful
mapping is possible, then the returned map contains an entry for each supplied Slack user ID.

**Signature**

```java
public Map<String, String> getSalesforceUserIdMap(List<String> slackUserIds)
```

**Parameters**

_slackUserIds_

Type: List\<String\>

**Return Value**

Type: Map<String, String>

#### getSlackUserId()

Gets the Slack user ID for a given Salesforce ID within a Slack workspace. If you’re calling from an Enterprise organization, make sure that you pass your Slack Enterprise ID for the `teamId` parameter. See [Slack’s `team.info` method](https://docs.slack.dev/reference/methods/team.info/).

**Signature**

```java
public String getSlackUserId(String salesforceUserId, String teamId)
```

**Parameters**

_salesforceUserId_

Type: String

_teamId_

Type: String

**Return Value**

Type: String

#### getSlackUserIdMap()

Given a list of Salesforce user IDs in a Slack workspace for a specific Slack App, get
the associated Slack user mappings. If at least one successful mapping is possible, then the returned
map contains an entry for each supplied Salesforce user ID. If you’re calling from an Enterprise organization, make sure that you pass your Slack Enterprise ID for the `teamId` parameter. See [Slack’s `team.info` method](https://docs.slack.dev/reference/methods/team.info/).

**Signature**

```java
public Map<String, String> getSlackUserIdMap(List<String> salesforceUserIds, String teamId)
```

**Parameters**

_salesforceUserIds_

Type: List\<String\>

_teamId_

Type: String

**Return Value**

Type: Map<String, String>
