Import Contacts Into Salesforce
Learn how to take a CSV file of contacts and upload them to Salesforce.
Screenshot of the main flow from Anypoint Studio
At times, you may find that you need to connect one or more of your organization's on-premises systems with a SaaS such as Salesforce. Ideally, these independent systems would talk to each other and share data to enable automation of end-to-end business processes. Use Mule applications to facilitate communication between your on-prem system(s) and Salesforce. (Though this use case does not extend as far, you can also use Mule to facilitate communication between SaaS providers).
Example Use Case
Though a simple example, this application nonetheless employs complex functionality to demonstrate a basic use case. The application accepts CSV files which contain contact information – name, phone number, email – and uploads them into a Salesforce account, automatically inserting the correct data into each Salesforce field.
Set Up and Run the Example
Complete the following procedure to create, then run this example in your own instance of Anypoint Studio. Skip ahead to the next section if you prefer to simply examine this example via code snippets.
- Create the example application in Anypoint Studio. 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 contacts.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 contacts.csv file inside this folder.
- Click and drag the contacts.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 Contacts tab.
- Use the drop-down menu to display All Contacts, then scan your contacts for three new entries:
- Charles Bingley
- Fitzwilliam Darcy
- George Wickham
- Stop the Mule application by clicking the square, red terminate button in the Console.
- Delete the three sample contacts from your Salesforce account.
Examples to Try Next
|If you understood this example|
|Web Service Consumer - Learn how to consume an existing Web service.||View|
|If you struggled with this example|
|HTTP Request Response with Logger - Learn how to use Mule to build a simple HTTP request-response application.||View|