Work with UserMappingService

Use the UserMappingService class to query for existing user mappings stored in Salesforce. A Slack user mapping is created when a user links their Salesforce and Slack accounts in these ways.

A user may have more than one mapping if they connect several Slack accounts to a Salesforce account.

UserMappingService Class 

Usage

1// UserMappingService.getSalesforceUserId
2String salesforceUserId = Slack.UserMappingService.getSalesforceUserId('U000000001');
3System.assertEquals('005xx000001X7yjAAC', salesforceUserId);
4
5// UserMappingService.getSalesforceUserIdMap
6List<String> slackIds = new List<String> {'U000000001', 'U000100002', 'U000100003'};
7Map<String,String> resultMap = Slack.UserMappingService.getSalesforceUserIdMap(slackIds);
8System.assertEquals(3, resultMap.size());
9System.assertEquals('005xx000001X7yjAAC', resultMap.get('U000000001'));
10System.assertEquals('005xx000001X7ykAAC', resultMap.get('U000100002'));
11
12// UserMappingService.getSlackUserId
13String teamId = 'T020L1EJEG3';
14String slackId = Slack.UserMappingService.getSlackUserId('005xx000001X7yjAAC', teamId);
15System.assertEquals('U000000001', slackId);
16
17// UserMappingService.getSlackUserIdMap
18String teamId = 'T020L1EJEG3';
19List<String> salesforceIds = new List<String> {'005xx000001X7yjAAC', '005xx000001X7ykAAC', '005xx000001X7ylAAC'};
20Map<String,String> resultMap = Slack.UserMappingService.getSlackUserIdMap(salesforceIds, teamId);
21System.assertEquals(3, resultMap.size());
22System.assertEquals('U000000001', resultMap.get('005xx000001X7yjAAC'));
23System.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

1public 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

1public 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.

Signature

1public 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.

Signature

1public Map<String, String> getSlackUserIdMap(List<String> salesforceUserIds, String teamId)

Parameters

salesforceUserIds

Type: List<String>

teamId

Type: String

Return Value

Type: Map<String, String>

Beta Feature

This feature is not generally available. It is not part of your purchased Services. This feature is subject to change, may be discontinued with no notice at any time in SFDC’s sole discretion, and SFDC may never make this feature generally available. Make your purchase decisions only on the basis of generally available products and features. This feature is made available on an AS IS basis and use of this feature is at your sole risk.