Set Up Your SFDX Project

After you set up your development environment, configure your project definitions and create a scratch org for your first Slack app.

To configure your SFDX project definition:

  1. Open the project in VS Code.

  2. Open config/project-scratch-def.json. Add the SLACK feature to the list of features. SLACK is case-sensitive.

  3. Update sfdx-project.json with the login URL for your Dev Hub org. Use the my.salesforce version (Classic) of the URL, not a Lightning Experience one. For example, https://my-dev-domain.my.salesforce.com.

  4. Set sourceApiVersion to 54.0 or later.

Scratch orgs simplify your Slack app development and drive developer productivity and collaboration. You can only have 3 active orgs at once. By default, you can create up to 6 scratch orgs a day.

Scratch orgs are short-lived, development, and testing orgs that are similar to your production and sandbox orgs.

To create a scratch org:

  1. Sign up and configure the scratch org using the scratch org definition in project-scratch-def.json, and run this command.

    • --alias sets an alias for your scratch org username so that you can refer to it with a simpler name from other commands.
    • --set-default sets this org as the default scratch org for your project so that you don’t have to specify the target org with commands that require it.
    • --duration-days sets the duration of the scratch org to the maximum of 30 days, after which it's deleted and you lose access to it.
  2. After you create your scratch org, you can see it in your org list known to the CLI by running sf org list.

To see how many scratch orgs you're using, run sf org list limits --target-org <DevHub org username or alias> and search for ActiveScratchOrgs and DailyScratchOrgs in the output table. Alternatively, to view your Active scratch orgs, go to the App Launcher in Lightning Experience, enter Scratch to find All Scratch Orgs and Scratch Org Info.

  1. Capture your scratch org user information.

    1. With the username that was created for your new scratch org, generate a password for this new admin user. Record this password to help you log in to your scratch org later.
    • --target-org specifies your scratch org username. You can find this information in Scratch Org Info. Alternatively, use the scratch1 alias you created earlier.
    1. Next, determine the instance URL using the same username or alias. Save this info for later.
  2. Assign Slack permission sets to your scratch org user.

    1. Log in to your scratch org with your scratch org username and generated password. Alternatively, open your scratch org by running sf org open. Since you set this scratch org as the default using the --set-default flag in an earlier step, SFDX stores your authentication token and uses it to log in for you.
    2. Create a permission set with the same steps as Enable User Permissions in your scratch org. Make sure to select Connect Salesforce with Slack and Create and Update Second-Generation Packages. Assign the permission set to your scratch org user.

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

  1. Confirm your SFDX setup.

    1. Open VS Code, and create a file called SayHello.cls in force-app/main/default/classes. Copy and paste this code, and then save the file.
    1. Create the metadata file SayHello.cls-meta.xml in force-app/main/default/classes. Copy and paste this code, and then save the file.
    1. Deploy the source to the scratch org.

    When you deploy successfully, a summary is displayed. Next, deploy a Slack app to your scratch org.

If you receive an expired access or refresh token error, check that your scratch org is still valid and not expired.

Scratch Orgs