Illustrates how to use batch processing to import leads into a Salesforce instance.
Batch processing lets you split a payload into individual elements to process each individually. This functionality is particularly useful when working with streaming input or when engineering "near real-time" data integration between SaaS applications.
This example uses batch processing to address a use case in which the contents of a comma-separated value file (CSV) of leads – comprised of names, birthdays, and email addresses – must be uploaded to Salesforce. To avoid duplicating any leads, the batch job checks to see if a lead exists before uploading data to Salesforce.
Set Up and Run the Example
Complete the following procedure to create, then run this example in your own instance of Anypoint Studio. You can create template applications straight out of the box in Anypoint Studio and tweak the configurations of this use case-based template to create your own customized applications in Mule.
- Open the Example project in Anypoint Studio from Anypoint Exchange. Do not run the application.
- Log in to your Salesforce account. From your account menu (your account is labeled with your name), select Setup.
- In the left navigation bar, under the Personal Setup heading, click to expand the My Personal Information folder.
- Click Reset My Security Token. Salesforce resets the token and emails you the new one.
- Access the email that Salesforce sent and copy the new token onto your local clipboard.
- In your application in Studio, click the Global Elements tab.
- Double-click the Salesforce global element to open its Global Element Properties panel. In the Security Token field, paste the new Salesforce token you copied from the email. Alternatively, configure the global element in the XML Editor.
- Change the contents of the Username and Password fields to your account-specific values, then click OK to save your changes.
- In the Package Explorer, right-click the connect-with-salesforce project name, then select Run As > Mule Application. Studio runs the application on the embedded server.
- This project includes a sample CSV file, called leads.csv, that you can use to witness end-to-end functionality of the application. In the Package Explorer, click the src/main/resources folder to expand it, then find the leads.csv file inside this folder.
- Copy the leads.csv file into an input folder in the same directory.
- The File connector in the application polls the input folder every ten seconds. It picks up the CSV file, processes it, then deposits it into the output folder in the same directory. (Hit F5 to refresh the contents of the input and output folders.)
- In your browser, access your Salesforce account, then navigate to the Leads tab.
- Use the drop-down menu to display All Open Leads, then scan your leads for the new entries:
- Ishmael Alexander
- Cole Burks
- Stop the Mule application by clicking the square, red terminate button in the Console.
- Delete the two sample leads from your Salesforce account.