Contact Us 1-800-596-4880

Create a Configuration File for Slack and Salesforce

logo cloud IDE Cloud IDE

logo desktop IDE Desktop IDE

Open Beta Release: The cloud IDE is in open beta. Any use of Anypoint Code Builder in its beta state is subject to the applicable beta services terms and conditions, available from the IDE.

A configuration file is a YAML file that can reference different configurations and specify different values for your connector properties. Configuration files enable you to define specific properties depending on the environment to which you are deploying your application.

To start configuring your Slack and Salesforce connectors in your escalation API, create a configuration file.

Create a Configuration File

  1. In your Explorer view, right-click the resources folder (src/main/resources) and select New File:

    contact sync integration new file
  2. Name the file config.yaml.

  3. Populate your file with your Salesforce, Gmail, and Slack configurations:

    salesforce:
     username: "yourUserName"
     password: "yourPassword"
     token: "yourToken"
    
    email:
     host: "smtp.gmail.com"
     username: "yourGmailEmail"
     password: "yourEmailAppPassword"
    
    slack:
     token: "yourSlackToken"
  4. Navigate to your new-case-salesforce.xml file, add a new line before the </mule> tag, type configuration and select mule:configurationProperties:

    select mule config properties contacts sync
  5. Scroll through the attributes and set the value of file to config.yaml:

    <configuration-properties file="config.yaml" doc:name="Configuration properties" />

Configure Your Salesforce Connector

Use the values in your config.yaml file to connect the Salesforce Connector to your Salesforce environment:

  1. In your new-case-salesforce.xml file, create a new line after the <configuration-properties/> element, type salesforce, and select salesforce:sfdc-config:

    sync api select sfdc config
  2. Set the name field to Salesforce-Config.

  3. Create a new line, type basic and select Salesforce:Basic:

    basic auth sfdc connector
  4. Configure the username and password properties to use your configuration file values:

    <salesforce:basic-connection username="${salesforce.username}" password="${salesforce.password}" securityToken="${salesforce.token}" />

    When you move your cursor over the ${salesforce.username} and ${salesforce.password} elements, Anypoint Code Builder shows the values from the configuration file.

  5. Verify your connection to Salesforce by clicking Test Connection for the <salesforce:sfdc-config/> element:

    sync api sfdc test connection

    Anypoint Code Builder returns a Connection is valid message.

    If you get an error, verify the error message to troubleshoot further.

Add a Salesforce Trigger

  1. Add a new flow on your canvas.

  2. In the code editor, name the flow ​NewSalesforceCaseFlow:

    <flow name="​NewSalesforceCaseFlow">
    
    </flow>
  3. On your canvas, click the (Add component) icon after Flow, type new object, and select On new object after Salesforce.

  4. In the code editor, set the following values of the <salesforce:new-object-listener/> element:

    • objectType: Case

    • config-ref: Salesforce-Config

    • name: On New Case

  5. In the <salesforce:new-object-listener/> element, replace <scheduling-strategy/> with the following snippet:

    <scheduling-strategy >
      <fixed-frequency frequency="1000"/>
    </scheduling-strategy>

Test Your Salesforce Integration

  1. Add a logger at the end of your flow:

    add logger end flow canvas
    drag logger canvas

    A logger component is added to the flow snippet in the code editor.

  2. Replace the logger component in the code editor with the following:

    <logger level="INFO" doc:name="Log Case Object" message="{#payload}" />
  3. Add a breakpoint to this line by clicking the red dot at the line number:

    logger breakpoint sfdc

    Alternatively, add a breakpoint to the logger component by right-clicking on the component in the canvas UI and selecting Add Breakpoint.

  4. Select Run > Start Debugging (F5).

  5. After your application deploys successfully, log in to your Salesforce account.

  6. From App Launcher, select Service:

    salesforce select service
  7. Select Cases > New Case:

    salesfroce create new case
  8. Ensure that the Status of the new case is New.

  9. Create a new case and save it.

  10. In Anypoint Code Builder, your application stops at the logger. Inspect the payload in Variables:

    slack app debugger logger breakpoint

    The payload contains information about your newly created case.

  11. Step over your Logger component.

  12. Proceed to Extract Payload Information to Variables to learn how to extract your case information to a variable to use it later in the flow.