Salesforce to Slack integration

The objective of these exercises is to receive notifications in Slack when new leads are added in Salesforce. This demonstrates a cloud-to-cloud integration. The integration occurs by:

  • Setting up integration to Salesforce and Slack in Application Integration's Integration Builder
  • Defining a flow in Integration Builder that specifies the path for new sales leads in Salesforce to reach Slack

Complete the tasks in the order presented.

Complete the prerequisites before you begin. 

Time to complete: 25 minutes

When completing fields in Integration Builder, make sure there aren't any spaces preceding values. Leading spaces are invalid.

Add a channel in Slack

Add a channel named leads in Slack. Remain logged on to review notifications from Salesforce later.

Add a Salesforce connector in Integration Builder

Perform the following steps in Integration Builder.

  1. On the AMPLIFY Platform find the Application Integration tile on the home page and open Integration Builder.
  2. Select Connectors in the left pane.
  3. Find the Salesforce Sales Cloud connector. You can search for it by typing all or part of the connector name in the search field.
  4. Place the cursor over the Salesforce Sales Cloud tile and click Authenticate.
  5. Type a name for the connector instance. For example, Salesforce connector for exercise.
  6. Skip the Authentication Type and Connector Instance Tag fields. 
  7. Under Event Configuration:
    • Click the toggle to turn on Events Enabled.
    • Select polling in the Event Type drop-down.
    • Type 12345 in the 
    • Type Lead in the Objects to Monitor for Changes field.
    • Scroll down to Event poller refresh interval (mins). Click and hold to slide the value to 1 minute.
  8. Click Create Instance. You are prompted to log on to Salesforce.
  9. Enter your Salesforce user name and password to log on.
  10. Click Allow when prompted to allow access. You are returned to Integration Builder.

Add a Slack connector in Integration Builder

Once you have added the Salesforce connector in the preceding steps, perform the following steps in Integration Builder.

  1. Select Connectors in the left pane in Integration Builder.
  2. Find the Slack connector. You can search for it by typing all or part of the connector name in the search field.
  3. Place the cursor over the Slack tile and click Authenticate.
  4. Type a name for the connector instance. For example, Slack connector for exercise.
  5. Do not change anything else.
  6. Click Create Instance. You are prompted to authorize Slack.
  7. Click Authorize. You are returned to Integration Builder.

Add a flow in Integration Builder (part 1 of 4)

Once you have added the Salesforce and Slack connectors in the preceding steps, perform the following  steps in Integration Builder.

There are four parts to adding the flow. Complete all four in order using Integration Builder.

  1. Select Flows in the left pane in Integration Builder.
  2. Click Build New Flow Template. Options for adding flows are displayed.
  3. Click Build New Flow.
  4. Type a name for the flow when prompted. For example, Salesforce to Slack exercise.
  5. Click Create. You are prompted to select the type of trigger that will start the flow.
  6. Click Add Event in the Event tile. An Edit Event: "trigger" pane is displayed on the right.
  7. Type ${config.source} when prompted for a connector instance variable.
  8. Click Save. A flow diagram like the following is displayed. You add to this flow in later steps.

Add the flow variables (part 2 of 4)

Add variables to use in the flow. The following table describes the three variables needed. Refer to the table when adding the variables.

Variable name Type Description
source Connector instance Source application, which is Salesforce in this exercise.
messaging Connector instance Messaging application, which is Slack in this exercise.
channel Value Name of the Slack channel to receive notifications from Salesforce. The channel is named leads in this exercise.

The following are the steps for adding a variable.

  1. With the Salesforce to Slack exercise flow open, click Variables at top right. A Flow Variables pane is displayed on the right.
  2. Click Create New Variable if not already selected.
  3. Click the correct type for the variable you are adding.
  4. Type the variable name when prompted.
  5. Click Save.
  6. Repeat until all three variables have been added.

Continue to configure the flow (part 3 of 4)

  1. In the flow diagram created earlier, click + below the trigger step to add another step in the flow. An Add Flow Step pane is displayed on the right.
  2. Click Create New if not already selected.
  3. Click Connector API Request as the type of flow step to add. A Create Connector API Request step pane is displayed.
  4. Complete the following fields with the provided values and click Save:
    • Name: getSalesforceLeadInfo
    • Connector Instance Variable: ${config.source}
    • Method: Select GET from the drop-down list
    • API: /leads/${trigger.event.objectId}
  5. Click the new getSalesforceLeadInfo step in the flow to show a menu. Click ADD ONSUCCESS. An Add Flow Step pane is displayed on the right.
  6. Click JS Script. A Create JS Script pane is displayed.
  7. Do the following:
    • Type createSlackMessageBody as the name.
    • Copy the following script, paste it in window below the name and click Save.
const l = steps.getSalesforceLeadInfo.response.body;
const s = "Salesforce";
const name = l.FirstName + " " + l.LastName;
const message = {
"text" : "A new lead, " + "'" + name + "'" + " has arrived in " + s + "!"
};
done(message);

Complete the flow (part 4 of 4)

  1. Click the new createSlackMessageBody step in the flow to show a menu. Click ADD ONSUCCESS. An Add Flow Step pane is displayed on the right.
  2. Click Connector API Request as the type of flow step to add. A Create Connector API Request step pane is displayed.
  3. Complete the following fields with the provided values and click Save:
    • Name: sendSlackMessage
    • Connector Instance Variable: ${config.messaging}
    • Method: Select POST from the drop-down list
    • API:  /channels/${config.channel}/messages
    • Under Show Advanced, Body: ${steps.createSlackMessageBody}

The completed flow diagram should look like the following:

Create an instance of the flow

Once the flow has been completed, perform the following steps.

Think of the flow you created as a template. Using the flow requires creating an instance of the flow template.

  1. Click Flows in the left pane to open the page that shows all flows.
  2. Find the Salesforce to Slack exercise flow. You can search for it by typing all or part of the flow name in the search field.
  3. Place the cursor over the Salesforce to Slack exercise tile and click Create Instance. Three variables tiles are displayed. These are the variables you created earlier.
    • source
    • messaging
    • channel
  4. Type a name for the flow instance. For example, exercise flow instance.
  5. In the source tile click + to select a connector instance. Click Salesforce connector for exercise.
  6. In the messaging tile click + to select a connector instance. Click Slack connector for exercise.
  7. In the Values tile for channel type leads, which is the name of the Slack channel in this exercise.
  8. Click Create Instance.

Any time you want to verify the presence of the instances of connectors or flows you have added, click Instances on the left pane. Click Connector or Flow at the top to show lists of connectors or flows instances.

Test

Once all configuration has been completed, perform the following steps to test whether Slack receives notifications from Salesforce of new sales leads.

  1. Add a lead in Salesforce.
    • Select Leads > New Lead on the top menu bar.
    • Type a first and last name for the lead and the lead's company name. Click Save
  2. Check whether Slack has received a notification in the leads channel.

As you set the polling interval for 1 minute, it might take that long for the event to trigger. 

You can monitor the flow execution in Integration Builder.

  1. Click Instances in the left pane.
  2. Click Flow.
  3. Find the flow instance in the list and click Executions.
  4. Click an object ID tile to reveal execution step tiles.
  5. Click a step tile to show details.

Related Links