Automate Slack Messages
Create Your Slack Workspace
In this step, you need a Slack workspace, as well as the email address and password you use to sign in to Slack. As you build out the integration, it’s best you use a test workspace, similar to using a Sandbox to test new Salesforce features.
Follow these steps to create one for free.
- Head to https://slack.com/
- You have the option to launch Slack or get started, depending on whether you already have Slack for work.
- If you’re new to Slack, click
at the top of the page, then click Create a Slack workspace.
- If you already have a Slack account, the website might recognize your browser. In this case, click
at the top of the page, then select Create a Slack workspace.
- If you’re new to Slack, click
- Follow the prompts to set up your account and new workspace.
- When Slack asks for the name of your company or project, enter something fun, like your pet or your favorite food.
- When Slack asks what you'll be using the workspace for, enter
announcements
and anything else you'd like to add. - When you get the prompt to add people, click Skip this step, then confirm by clicking Skip Step to go right into your workspace.
You now have a new Slack workspace. To access your exact workspace address, click the disclosure arrow (1) next to your business or team name (what you named the workspace), and check out the address next to the large initials (2). It should be in this format: workspace.slack.com
Create a Slack Channel for Leads
Once your workspace is set up, create a new channel in Slack for all your lead alerts.
- Click the + next to Channels.
- Select Create a channel from the dropdown.
- Enter
leads
for the channel name, then click Create. - Toggle on the option to auto-add anyone who joins your workspace.
- Then, click Save.
Now, head back to your Trailhead Playground to finish the setup.
Create Custom Message Destinations
Custom message destinations guide alerts to your specific Slack workspace. Head back to your Trailhead Playground and open the Slack Setup app if it’s not open already. The app should indicate Automation Configuration is next. Click Continue to start.
- Click Sign in with Slack to open the popup and authenticate your Slack workspace.
- Slack may recognize your browser, in which case you only need to select the appropriate workspace and click Allow.
- If Slack doesn’t recognize your browser:
- Enter the Slack workspace and click Continue.
- Enter the email address and password you set up for Slack and click Sign In. If you need help finding your password, you can check out this article from Slack.
- Then, click Allow.
- Click New Message Destination and enter the following:
- Message Destination Name:
Leads
- Slack Workspace: leave as-is (it should be the workspace you authenticated)
- Slack Channel or Person: leads
- Message Destination Name:
- Click Save.
- Click
to the right of the message destination ID to copy it. Save in a place where you can retrieve it later.
- Then, click Finish.
Build Automation with Process Builder
Once you've set up a message destination, build a process to automatically send new leads to Slack.
- Click
and select Setup.
- Enter
process
in Quick Find and select Process Builder. - Click New to start your new automation.
- Enter
Slack Leads
for Process Name. This should automatically populate the API name, too. - For The Process starts when, select A record changes.
- Click Save.
Automate New Leads
Set up the process so that it activates when new leads are created.
- Click Add Object.
- In the prompt, enter
lead
in the Find an object … field and select Lead. - To start the process, make sure only when a record is created is selected.
- Click Save.
- Then, click Add Criteria.
- Enter
Record Creation
for Criteria Name. - Make sure No criteria—just execute the actions! is selected.
- Click Save.
Add a Message for Context
Now, make the action send a message to Slack with key information and a fun message.
- Click Add Action, then enter the following information:
- Action Type: Apex
- Action Name:
send to slack
- Apex Class: Slack: Post Message
- The Apex Class opens a set of field variables. This is where you add your message destination ID and other information.
- Record ID | Field Reference | click into Find a Field, enter
lead
in the search, and select Lead ID, then click Choose. - Message Destination ID | ID | enter the destination ID you copied from your message destination above.
- Record ID | Field Reference | click into Find a Field, enter
- Click Add Row for the last variable.
-
Message | String | enter
There’s a new lead in Salesforce!
-
Message | String | enter
- Click Save.
- Click Activate.
- Then, click Confirm.
Notice the process references a specific Apex Class, Slack: Post Message. The Salesforce for Slack package created this class. It also set up an action for Flow Builder, just in case your business needs require the use of flows. Check out Lightning Flow for more information on best use cases for each automation tool.
OK, you’ve set up automation by building a flow. There’s only one thing you need to do now—test!