tree: 2089ae68fe78e3888a34cfe1bfece7958ad56709 [path history] [tgz]
  1. src/
  2. pom.xml

Twitter Salesforce Example


This example listen for tweets which are mentioning the @cameltweet twitter account. Information from the user whom mentions is then created as a contact in Salesforce.

Configuring Twitter

This example is already configured using a testing purpose twitter account named ‘cameltweet’. And therefore the example is ready to run out of the box.

This account is only for testing purpose, and should not be used in your custom applications. For that you need to setup and use your own twitter account.

Configuring Salesforce

This example uses Camels own test Salesforce developer account, you would most likely want to sign up with your own Developer account at 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

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

Adding the Twitter screen name custom field

The example adds a custom field to Contact SObject, to add it to your Salesforce environment go into Customize under Build and choose Fields under Contact.

In Contact Custom Fields & Relationships click on New and add a field of type Text with field label Twitter Screen Name, length of 15 and for uniqueness select Do not allow duplicate values and set the Set this field as the unique record identifier from an external system.

Getting the OAuth refresh token

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:<refresh_token>&instance_url=...&issued_at=...&signature=...&scope=...&token_type=Bearer

How to generate Salesforce Data Transfer Objects (DTOs)

The best way to generate Java representation of Salesforce SObjects is to use the camel-salesforce-maven-plugin, for example:

$ mvn org.apache.camel.maven:camel-salesforce-maven-plugin:generate \
  -DcamelSalesforce.clientId=<client id> \
  -DcamelSalesforce.clientSecret=<client secret> \
  -DcamelSalesforce.userName=<username> \

You can specify the only the SObjects you'll integrate with using camelSalesforce.includePattern parameter, like:

$ mvn org.apache.camel.maven:camel-salesforce-maven-plugin:generate \
  -DcamelSalesforce.clientId=<client id> \
  -DcamelSalesforce.clientSecret=<client secret> \
  -DcamelSalesforce.userName=<username> \
  -DcamelSalesforce.password=<password> \

To generate only DTOs needed for Contact, but the parameter value can be specified using regular expressions.


You will need to compile this example first:

mvn compile


To run the example type

mvn spring-boot:run

To stop the example hit ctrl+c

Forum, Help, etc

If you hit an problems please let us know on the Camel Forums

Please help us make Apache Camel better - we appreciate any feedback you may have. Enjoy!

The Camel riders!