This application uses pre-packaged tools to append data to a message payload and perceptively connect with Salesforce. The example takes a CSV file of new account information, figures out which region each account belongs to, appends region information to the payload, then uploads the new accounts to an active Salesforce user account. It uses Mule DataSense and Anypoint DataWeave to map and transform data, thereby facilitating quick integration with this Software-as-a-Service (SaaS) provider.
At times, you may find that you need to connect one or more of your organization's on-premise systems with an SaaS application, 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.)
Beyond transforming and mapping data from one format to another, you can use an Anypoint DataWeave Transformer to access other flows in a Mule application to acquire additional information. Use a flow lookup to acquire information outside the message, then append it to the payload.
This document describes the details of the example within the context of Anypoint Studio, Mule ESB’s graphical user interface, and includes configuration details for XML Editor where relevant.
The use case upon which this example is based represents a reasonably common requirement to upload new account information into Salesforce. From a CSV file containing information about new accounts (company name, billing address, etc.), a user wishes to use the addresses of the companies to determine the sales region to which each company belongs, then upload all the account details – including sales region – to Salesforce. This example Mule application performs these actions.
Complete the following procedures to create a custom field and the example application. Then, run this example in your own instance of Anypoint Studio. Skip ahead to the next section if you prefer simply to examine this example.
To see the end-to-end functionality, you must have an active Salesforce account into which you don't mind inserting a new custom field for "region" and two sample accounts. After this application automatically uploads these example customer accounts, you can manually delete them and the custom field from your Salesforce account.
Click New under the Account Custom Fields & Relationships section.
In Step 4, check the Account Layout box, then click Save.
Region\_\_cThis is the new field to which DataWeave will map the region data it acquires from another flow.
companies.csv, that you can use to see the 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.
dataweave-with-flow-referenceproject name, then select Run As > Mule Application. Studio runs the application on the embedded server. The File Endpoint in the application polls the input CSV file every ten seconds and processes it.
Using two flows, this application accepts CSV files which contain account information, uses the "state" data to append a sales region to the message, then uploads the contacts to Salesforce.
The Scheduler component triggers the CreateNewSalesforceAccountFlow every ten seconds. The File Component reads the input CSV file and passes its content to the Anypoint DataWeave Transformer. The Transformer converts the format of the data from CSV to a collection and maps the input fields from the CSV file – companyname, companyaddress, etc. – to output fields that Salesforce uses in a collection.
The DataWeave also utilizes a flow lookup. The llow lookup accesses another flow in the application to acquire the sales region for each new account. DataWeave invokes LookupSalesRegionFlow, which uses the companystate data to determine into which sales region the account falls. DataWeave then maps this newly acquired data to the custom field in Salesforce,
When it has converted all the account information in the file to a collection of Salesforce-friendly data, the application uses a Salesforce Connector to push data into your Salesforce account. The connector's configurations specify the operation – Create – and the sObject type – Account – which dictate exactly how the data uploads to Salesforce; in this case, it creates new accounts.
This flow consists of a Groovy component and a Logger. The script in the component uses state information in the message payload to calculate the sales region to which the account belongs. Invoked by the flow lookup in DataWeave, this flow exists only to determine a sales region for each account in the CSV file.
Studio includes a feature that enables you to easily export all the documentation you have recorded for your project. Whenever you want to share your project with others outside the Studio environment, you can export the project's documentation to print, email, or share online. Studio's auto-generated documentation includes:
Follow the procedure to export auto-generated Studio documentation.
|Published on||Jul 28, 2018|