This is the example demo from the Apache Camel & Salesforce talk given at the Berlin Salesforce Developer Group Meetup by Zoran Regvart.
Link to the slides is here.
NOTE: Make sure that you have performed the needed configuration outlined below.
NOTE: Make sure that you have enabled one of the routes either in
src/main/java/com/regvart/talks/salesforce/SalesforceToSlack.java
or in src/main/resources/camel/salesforce-to-slack.xml
- see the
comments provieded there on instructions.
NOTE: You need an Java 8 to run this example, install it if you haven't already.
To run set the environment variables:
Variable name | Value |
---|---|
SALESFORCE_CLIENTID | OAuth Consumer Key |
SALESFORCE_CLIENTSECRET | OAuth Consumer Secret |
SALESFORCE_REFRESHTOKEN | OAuth Refresh Token |
SLACK_WEBHOOKURL | Slack Incoming WebHook URL |
And run:
$ ./mvnw
Create a Lead in Salesforce and observe the message that arrives at the configured Slack channel.
To stop the example press ctrl+c.
To run the example you need access to a Salesforce developer account, you can sign up for your own Developer account at https://developer.salesforce.com/. After you have done that, you'll need to create a Connected Application for your integration.
To do this after logging in to your Salesforce Developer account, navigate to Apps located under Build and then Create, there you should see Connected Apps table in the heading click on New and fill in the indicated required fields and enable the OAuth Settings, for Callback URL you can use https://login.salesforce.com/services/oauth2/success.
In the Available OAuth Scopes add Access and manage your data (api) and Perform requests on your behalf at any time (refresh_token, offline_access).
After clicking Save click on Manage on the top of the page and then click on Edit Policies. Change the IP Relaxation to Relax IP restrictions and click on Save.
NOTE: This will get you started quicker, but production you should re-evaluate to comply with your security needs.
Next gather your Consumer Key (clientId property), Consumer Secret (clientSecret) and either use username and password of the developer account; or get the refresh token from Salesforce (more on this below).
To run the example you need to have the access to a Slack instance and
the ability to configure incoming WebHooks. Once logged in open
Apps & Integrations menu and search for Incoming WebHooks
. On the
Incoming WebHooks screen select Add Configuration and pick a channel
and continue by clicking on Add Incoming WebHooks integration and make
note of the Webhook URL provided.
In your browser go to the URL change the __YOUR_CLIENT_ID_HERE__
with your connected application Consumer Key:
Allow access to the application, and you'll end up on a page with
refresh_token
after the #
, something like:
https://login.salesforce.com/services/oauth2/success#access_token=..&refresh_token=
<refresh_token>&instance_url=...&issued_at=...&signature=...&scope=...&token_type=Bearer
You can regenerate the generated DTOs in src/generated/java
by
running the camel-salesforce-maven-plugin
:
$ ./mvnw -Pregenerate \
-DcamelSalesforce.clientId=<OAuth consumer key> \
-DcamelSalesforce.clientSecret=<OAuth consumer secret> \
-DcamelSalesforce.userName=<Salesforce username> \
-DcamelSalesforce.password=<Salesforce password> \
-DcamelSalesforce.includePattern=Lead
NOTE: Remember that if you're using Salesforce security token you need to append it to your Salesforce password.