Salesforce Data Retrieval

(1 review)

home

Illustrates how to use Mule Runtime to build a simple HTTP application to query Salesforce in a dynamic way. After reading this document, creating and running the example in Mule, you should be able to leverage what you have learned to create an HTTP request-response application that is able to retrieve requested data from Salesforce instance based on your criteria.

This example can also be used while configuring any of our Anypoint Salesforce Templates for retrieving all needed Salesforce entity ID's, such as selecting User as object, leaving Field empty, and querying by 'email'.

Prerequisites

This document describes the details of the example within the context of Anypoint Studio. This document assumes that you are familiar with Salesforce, Mule Runtime, and the Anypoint Studio interface.

Example Use Case

In this example, a user makes an HTTP request to the endpoint containing predefined set of parameters that are extracted and used while building a Salesforce query. Afterwards, the application receives the response and provides it to the end user.

Set Up and Run the Example

As with other examples, you can create template applications straight out of the box in Anypoint Studio. You can tweak the configurations of these use case-based examples to create your own customized applications in Mule.

Follow the procedure below to create, then run the Salesforce data retrieval application.

  1. Open the Example project in Anypoint Studio from Anypoint Exchange.
  2. In your application in Studio, click the Global Elements tab. Double-click the HTTP Listener global element to open its Global Element Properties panel. Change the contents of the port field to required HTTP port for example, 8081
  3. Go to Global Elements and open Salesforce Connector element. Fill in your Salesforce credentials including the security token.
  4. Run the application.
  5. Open your browser and hit http://localhost:8081. The form will be provided to you, containing following values:

    • Object - specify Salesforce object type, for example, User, Account, Contact, etc.
    • Field - a valid field name for the given object you need, for example, Email for Contact. IMPORTANT: ID and Name attributes are retrieved by default, so choosing these fields results in an invalid query.
    • Search Key - a valid field name for the given object you wil use for matching, for example Name for Contact.
    • Search Value - a value for the Search Key field that will be used for matching, e.g. young for Contact Name. All records that contain the Search Value value as a substring of the given Search Key field value are returned, i.e. contacts with names such as John Young or Michael Young will be returned. The more specific value, the less results you will obtain.
  6. Click Submit button.

  7. You will see the retrieved data structure.
  8. In case of invalid input, the message: Invalid Salesforce query.

If you are unsure about valid object types and their attributes, please visit Salesforce Documentation site - Standard Objects.

Example Use Case

To find out the correct sfdc.integration.user.id value, after you'll run the example, please fill in the following values to the form:

  • Object: User
  • Field: can be empty as Id field is displayed by default
  • Search Key: UserName
  • Search Value: bob.dylan@org (value of the sfdc.username)

The id field from the output represents the sfdc.integration.user.id of the specified user.

How it Works

The Salesforce data retrieval example application contains two flows which receive end user HTTP requests, process them and returns the result to the client.

The sections below elaborate further on the configurations of the application and how it works to respond to end user requests.

showFormFlow

This flow is responsible for displaying a submit form with some fields to build a Salesforce query, and listens at http://localhost:8081 for incoming HTTP GET requests. The Salesforce connector executes the Describe Global operation to gather all object types allowed for your organization in Salesforce.

The Expression block extracts names and labels of object types and transforms them into a HTML code to be used in a dropdown menu.

Finally, Parse Template component returns a specified HTML document containing the form.

salesforceIdRetrievalFlow

This flow makes use of five building blocks to receive and respond to an end user requests. When an end user request encounters the application, the first building block it meets is HTTP Listener. Because it has a two-way message exchange pattern, this HTTP endpoint is responsible for both receiving requests from and sending responses to the end user.

The Salesforce connector executes a query created using Mule Expression Language. Basically, parameters from the payload are extracted. The Expression block transforms Salesforce data structure into a list of objects that Mule moves back to the HTTP Listener which simply returns the message payload as the response to an end user in the form of HTML.

The Catch Exception Strategy is implemented to handle errors, such as using invalid Field value for the chosen Object type.


Reviews

TypeExample
OrganizationMuleSoft
Published by
MuleSoft Organization
Published onSep 6, 2018
Asset overview

Asset versions for 2.1.x

Asset versions
VersionActions
2.1.4
2.1.3
2.1.2

Categories

Products
SalesforceNo values left to add