Set Up Your Development Environment

Use Salesforce DX tools for an integrated development experience. Make sure you have a Slack workspace that you can deploy apps to.

To set up Salesforce DX tools:

  1. Set up Visual Studio Code.
  2. Install the Salesforce Extension Pack for Visual Studio Code. Salesforce Extension Pack provides powerful features for working with the Salesforce CLI, Apex, and other Salesforce platform features.
  3. Install the Salesforce CLI.

Next, get your Salesforce org ready for Slack development by following these steps.

A Dev Hub org enables you to create and manage scratch orgs.

You must also accept the Salesforce for Slack Beta Terms and Conditions to use Apex SDK for Slack.

To set up a Dev Hub org with My Domain enabled:

  1. Create a Developer Edition (DE) org if you don't already have one.

Contact Salesforce to enable Slack org permissions for this pilot program.

  1. Enable My Domain. An email is sent to you when the domain is ready. Log in from your domain, and deploy the domain to users.
  2. Enable Dev Hub in your org and select the Enable Unlocked Packages and Second-Generation Managed Packages option.

If you're working with second-generation managed packaging (2GP), see Distribute Slack Apps.

To enable user permission for developing Slack apps:

  1. From Setup, in the Quick Find box, enter Permission, and then select Permission Sets.
  2. Select an existing permission set, or create one.
  3. Under System Permissions, enable permission Connect Salesforce with Slack. If you're working with second-generation packages, enable permission Create and Update Second-Generation Packages as well. Click Save.
  4. Click Manage Assignments and assign the permission to your admin user.
  5. Click Done.

Connected apps use standard protocols like SAML, OAuth, and OpenID Connect to authenticate, authorize, and provide SSO for external apps.

  1. From Setup, in the Quick Find box, enter App, and then select App Manager.
  2. Click New Connected App.
  3. Update the required information as needed, such as the connected app name and your email address.
  4. Select Enable OAuth Settings.
  5. For the callback URL, enter http://localhost:1717/OauthRedirect. If port 1717 is already in use, specify an available one instead. See Create a Connected App for Your Dev Hub Org.
  6. Add these OAuth Scopes:
    1. Manage user data via APIs (api)
    2. Manage user data via Web browsers (web)
    3. Perform requests at any time (refresh_token, offline_access)
  7. Click Save.

To authenticate to your org from the CLI:

  1. Use a terminal to cd to a location.

  2. Create an SFDX project using this command.

  3. Go to your project.

  4. Authenticate to your org.

    • This command opens a browser using the URL specified by -r. Use the my.salesforce version (Classic) of the URL, not a Lightning Experience one.
    • -a sets an alias for your DevHub org username so that you can refer to it with a simpler name from other commands.
    • -d sets this org as the default DevHub org for your project so that you can omit the target DevHub org for commands that require it.
  5. Log in with the username and password from the org you just made. Allow access to the org from the CLI.

The command exits in your shell when the authentication is successful.

You can see your authenticated orgs by running sfdx force:org:list. If you must authenticate to your dev hub org again, run sfdx force:auth:web:login --setdefaultdevhubusername.

Now that you authenticated to your Dev Hub org, you can run your Slack app with Apex.