Reading Time: 7 minutes
Salesforce

SalesForce.com has been a pioneer in the software as service(SaaS) space. By offering a reliable and highly flexible interface they have grown to a company with revenues of over a billion dollars a year. Currently today many companies store their system of record in SalesForce or at the very least use it for management of all customer accounts and opportunities. With such valuable information it isn't any surprise that the need to integrate SalesForce with other systems in the enterprise is highly desirable. In this post I will take you though the use of with SalesForce.

First, lets get things setup, the best place to find the needed connectors for Mule is by searching the MuleForge. There we can find information about the SalesForce connector which is located here.

latest report
Learn why we are the Leaders in management and

Once we are setup with a development account and have installed the software as talked about in the documentation we can then proceed. In this specific example we will be querying SalesForce for new accounts that are created or updated and then update our local database. The first step is setting up the database which we will be inserting the records into and setting up the connection to SalesForce:

Here I'm using the JDBC connector in Mule to connect to a local MySQL instance. For my INSERT statement I'm also making use of MySQL's ““ON DUPLICATE KEY UPDATE”” feature. This will come in handy later.

Now let's start building our flow:

At the start of the flow I'm making use of the element that allows me to execute any message processor on a periodic basis. Here I have it specified to execute every 5 minutes. Within the element I'm executing the GetUpdated function which gives me back all newly created or updated objects for a specific type. Also on the call I specify the duration of how far back I wish to retrieve the recently updated objects for. In this example I specify 6 minutes to make sure I don't miss any objects and the database can handle any duplicates since we specified “ON DUPLICATE KEY UPDATE” in the SQL. From the call to GetUpdated the ids of the recently updated or created accounts are returned which I'll make use of in the next step.

Splitting Things Up

Now that I have an array of the ids that have been newly created or updated I want to split them up into individual messages. I can easily do this using the configuration element in Mule while also making use of the OGNL evaluator which allows me to easily access variables and methods on a Java object. So lets take a look at our flow now:

Filling in the Blanks

Before I do my insertion into my database I have to get more than just the ids of the object I wish to update/insert. To do this I can make a query to SalesForce using SOQL in combination with the id I retrieved from the GetUpdated call. A query call can retrieve back multiple results but in this case I will only ever have a single result being returned so I make use of a transform to set the payload of the message to the be first item in the array.

The Finish Line

Now that I have the result of the query, which is a map of keys and values, I can easily reference them in my SQL statement to MySQL using the map-payload evaluator. Then lastly we can perform the insertion into the database. Lets see what the complete flow looks like:

I hope you have you enjoyed this example and stay tuned as we continue to expand the support for SalesForce within Mule!