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.

Configure Your Project Definitions 

To configure your SFDX project definition:

  1. Open the project in VS Code.

  2. 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.

    1"sfdcLoginUrl": "https://<my_domain>.my.salesforce.com",
  3. Set sourceApiVersion to 54.0 or later.

    1"sourceApiVersion": "54.0",

Create a Scratch Org 

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.

Note

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.

    1sf org create scratch --definition-file config/project-scratch-def.json --alias scratch1 --set-default --duration-days 30
    • --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.

Tip

  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.
    1sf org generate password --target-org scratch1
    • --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.
    1sf org display user --target-org scratch1
  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.

Important

  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// SayHello.cls
    2public class SayHello {
    3   public String hello() {
    4      return 'Hello World!';
    5   }
    6}
    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<?xml version="1.0" encoding="UTF-8"?>
    2<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
    3 <apiVersion>54.0</apiVersion>
    4 <status>Active</status>
    5</ApexClass>
    1. Deploy the source to the scratch org.
    1sf project deploy start

    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.

Tip

See Also 

Scratch Orgs

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.