The Slack Mass User Provisioning API allows bulk import and the ability to revoke user mappings between a Salesforce and Slack user. This feature is helpful for organizations with larger user lists.
A user who has the Connect Salesforce with Slack and the Manage Slack user mappings permissions enabled and assigned.
Access to a list of user mappings of Salesforce user id to Slack user id.
Importing User Mappings
To import user mappings you must know the Salesforce and the Slack User IDs. Using the known IDs, create a list of user mappings with the Slack.UserMapping object.
1List<Slack.UserMapping>mappings = new List<Slack.UserMapping>();2mappings.add(new Slack.UserMapping(salesforceUserId, slackUserId));
After you have a list of mappings, use the Slack.UserProvisioningProvider to import the users for the workspace.
When the call to importUsers is complete, the API returns a result object that contains a list of successful mappings and a list of unsuccessful mappings.
1Slack.UserProvisioningResult result = Slack.UserProvisioningProvider.importUsers(mappings, workspaceId);2List<Slack.UserMappingResult>successfulMappings = result.getSuccessfulMappings();3List<Slack.UserMappingResult>failedMappings = result.getFailedMappings();
Each unsuccessful mapping has a failure code and message associated with it. Mappings can fail because of an invalid Salesforce ID, an invalid Slack ID, or a previous mapping.
Important: Use of Slack.UserProvisioningProvider is limited to Salesforce users with the Enable Slack User Pre-mapping API user permission. A user without this permission gets an exception during execution.
Example - Import Users
This code sample uses the API to create a single user mapping. The Slack user ID and Salesforce user ID of the mapping is already known.
1// needed information - workspace id, salesforce user id, slack user id2String workspaceId = 'T0000000001';3String salesforceUserId = '005xx000001X7yjAAC';4String slackUserId = 'U000000001';56// create a list of user mappings between salesforce and slack ids7List<Slack.UserMapping>mappings = new List<Slack.UserMapping>();8mappings.add(new Slack.UserMapping(salesforceUserId, slackUserId));910// import the user mappings11Slack.UserProvisioningResult result =12 Slack.UserProvisioningProvider.importUsers(mappings, workspaceId);1314// assert the results15List<Slack.UserMappingResult>successfulMappings = result.getSuccessfulMappings();16List<Slack.UserMappingResult>failedMappings = result.getFailedMappings();17System.debug('Number of successful mappings: ' + successfulMappings.size());18System.debug('Number of failed mappings: ' + failedMappings.size());
Revoking User Mappings
Individual mappings can be revoked by providing the Salesforce user ID and the team or workspace that they’re associated with or the Slack user id. Using the known user id, you create a list of strings of either the Salesforce user id or the Slack user id.
1List<String>salesforceIdsToRevoke = new List<String>();2salesforceIdsToRevoke.add(salesforceUserId);
After you have a list of user ids, use the Slack.UserProvisioningProvider to revoke the users based on id type for the workspace.
1// revoke by salesforce id2Slack.UserProvisioningProvider.revokeUsersBySalesforceId(salesforceIdsToRevoke, workspaceId);3// revoke by slack id4Slack.UserProvisioningProvider.revokeUsersBySlackId(slackIdsToRevoke);
After the call to revoke users is complete, the API returns a result object containing a list of successful mappings and a list of unsuccessful mappings.
1Slack.UserProvisioningResult result = Slack.UserProvisioningProvider.revokeUsersBySalesforceId(salesforceIdsToRevoke, workspaceId);2List<Slack.UserMappingResult>successfulRevokedMappings = result.getSuccessfulMappings();3List<Slack.UserMappingResult>failedRevokedMappings = result.getFailedMappings();
Each unsuccessful revoked mapping has a failure code and message associated with it. Revoked mappings fail because of an invalid Salesforce ID, an invalid Slack ID, or a non-existent user mapping.
Important: Use of Slack.UserProvisioningProvider is limited to Salesforce users with the Enable Slack User Pre-mapping API user permission. A user without this permission gets an exception during execution.
Example - Revoke by Salesforce User Id
1// needed information - workspace id, salesforce user id2String workspaceId = 'T0000000001';3String salesforceUserId = '005xx000001X7yjAAC';45// create a list of user mappings between salesforce and slack ids6List<String>salesforceIdsToRevoke = new List<String>();7salesforceIdsToRevoke.add(salesforceUserId);89// revoke the user mappings10Slack.UserProvisioningResult result =11Slack.UserProvisioningProvider.revokeUsersBySalesforceId(salesforceIdsToRevoke, workspaceId);1213// assert the results14List<Slack.UserMappingResult>successfulRevokedMappings = result.getSuccessfulMappings();15List<Slack.UserMappingResult>failedRevokedMappings = result.getFailedMappings();16System.debug('Number of successful revoked mappings: ' + successfulRevokedMappings.size());17System.debug('Number of failed revoked mappings: ' + failedRevokedMappings.size());
Example - Revoke by Slack User Id
1// needed information - slack user id2String slackUserId = 'U000000001';34// create a list of user mappings between salesforce and slack ids5List<String>slackIdsToRevoke = new List<String>();6slackIdsToRevoke.add(slackUserId);78// revoke the user mappings9Slack.UserProvisioningResult result =10Slack.UserProvisioningProvider.revokeUsersBySlackId(slackIdsToRevoke);1112// assert the results13List<Slack.UserMappingResult>successfulRevokedMappings = result.getSuccessfulMappings();14List<Slack.UserMappingResult>failedRevokedMappings = result.getFailedMappings();15System.debug('Number of successful revoked mappings: ' + successfulRevokedMappings.size());16System.debug('Number of failed revoked mappings: ' + failedRevokedMappings.size());
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.