Nav
You are viewing an older version of this section. Click here to navigate to the latest version.

Salesforce Analytics Cloud Connector

The Anypoint Connector for Salesforce Analytics Cloud lets you connect to the Salesforce Analytics Cloud application using SOAP API. The connector exposes convenient methods for creating data sets in Salesforce Analytics Cloud from different data sources, such as XML, CSV, and a list of Map objects.

Prerequisites

This document assumes you are familiar with Mule, Anypoint Connectors , and Anypoint Studio Essentials To increase your familiarity with Studio, consider completing one or more Anypoint Studio Tutorials. Further, this page assumes that you have a basic understanding of Mule flows and Mule Global Elements.

To use the Salesforce Analytics Cloud connector, you must have a Salesforce account and necessary permissions for uploading data into analytics cloud. For more information see Analytics Cloud Overview and Analytics Cloud External Data API Developer’s Guide.

Compatibility

The Salesforce Analytics Cloud connector is compatible with:

Application/Service Version

Mule Runtime

3.5.0 or later

Salesforce API

v31

SOAP API

v31

Installing and Configuring

Installing

You can install a connector in Anypoint Studio using the instructions in Installing a Connector from Anypoint Exchange.

Creating a New Project

To use the Salesforce Analytics Cloud connector in a Mule application project:

  1. In Studio, select File > New > Mule Project.

    PS_0001B_installing_new

  2. Enter a name for your new project and leave the remaining options with their default values.

    newProject

  3. If you plan to use Git, select Create a .gitignore file for the project with default ignores for Studio Projects, and then click Next.

  4. Click Finish to create the project.

Configuring the Salesforce Analytics Cloud Global Element

To use the Salesforce Analytics Cloud connector in your Mule application, you must configure a global Salesforce Analytics Cloud element that can be used by all the Salesforce Analytics Cloud connectors in the application (read more about global elements).

Salesforce Analytics Cloud Connector Authentication

To access the data in a Salesforce Analytics Cloud instance, you need to authenticate your application’s requests using basic authentication or OAuth.

Basic authentication is the easiest to implement. All you need to do is provide your credentials in a global configuration, then reference the global configuration in any Salesforce Analytics Cloud connector in your application. Basic authentication is generally recommended for internal applications. Implementing OAuth, on the other hand, involves a few extra steps, but may be preferred if your service is exposed to external users, as it ensures better security.

For an in-depth explanation of how to connect to Salesforce Analytics Cloud applications through OAuth, refer to Analytics Cloud External Data API Developer’s Guide and Using a Connector to Access an OAuth API.

  1. Click the Global Elements tab at the base of the canvas.

  2. On the Global Mule Configuration Elements screen, click Create.

  3. In the Choose Global Type wizard, expand Connector Configuration, and then select Salesforce Analytics Cloud: Basic Authentication or Salesforce Analytics Cloud (OAuth) depending on your Salesforce Analytics implementation.

    global+type

  4. Click OK

  5. Enter the global element properties: 

    1. For Salesforce Analytics Cloud: Basic Authentication:

      basic+authentication

      In the image above, the placeholder values refer to a configuration file placed in the src folder of your project (Learn how to configure properties). You can either hardcode your credentials into the global configuration properties, or reference a configuration file that contains these values. For simpler maintenance and better re-usability of your project, Mule recommends that you use a configuration file. Keeping these values in a separate file is useful if you need to deploy to different environments, such as production, development, and QA, where your access credentials differ. See Deploying to Multiple Environments for instructions on how to manage this.

      Field Description

      Name

      Enter a name for this connector to reference it later.

      Username

      Enter a Salesforce Analytics Cloud username.

      Password

      Enter the corresponding password.

      Security Token

      Enter the Security Token for the username.

      Do not confuse the Security Token required in Basic Authentication with the one required in OAuth authentication.

      Here, the token refers to your user, not to your application, as it does in OAuth.

      Enable DataSense

      When enabled, DataSense  extracts metadata for Salesforce Analytics Cloud objects to automatically determine the data type and format that your application must deliver to, or can expect from, Salesforce Analytics Cloud system. By enabling this functionality, Mule discovers the type of data you must send to, or receive from Salesforce Analytics.

      Metadata File Name

      Enter the path for the file that contains the descriptions of the object structure of the row that is uploaded into the Salesforce Analytics Cloud system. This path has to be relative to src/main/resource dir.

      Metadata File Type

      Select the type of the metadata file.

  6. For Salesforce Analytics Cloud: Salesforce Analytics Cloud (OAuth):

    1. On the General tab, configure the following fields:

      OAuth

      Field Description

      Consumer Key

      Enter the consumer key for the connector to access Salesforce Analytics.

      Consumer Secret

      Enter the consumer secret for the connector to access Salesforce Analytics.

      On No Token

      Select the action that the connector must take if it finds no access token.

      Metadata File Name

      Enter the path for the file that contains the descriptions of the object structure of the row that is uploaded into the Salesforce Analytics Cloud system. This path has to be relative path to src/main/resource dir.

      Metadata File Type

      Select the type of the metadata file.

    2. On the OAuth tab, configure the following fields:

      oauthtab

      Field Description

      Domain

      Enter the domain name to use as the callback endpoint. The domain name is not a full URL, but a domain name, IP address, or a hostname.

      Local Port

      Enter the local port to use for the callback endpoint.

      Remote Port

      Enter the remote port to use to build the callback URL.

      Path

      Enter the path to use for the callback endpoint.

      Http Connector Reference

      Enter the HTTP Connector Reference to use for the callback endpoint.

      Default Access Token Id

      Enter the Mule Expression to use as an access token.

      Object Store Reference

      Enter the name of the Object Store Reference.

  7. Keep the Pooling Profile  and the  Reconnection  tabs with their default entries.

  8. Click Test Connection to confirm that the parameters of your global Salesforce Analytics Cloud connector are accurate, and that Mule is able to successfully connect to your instance of Salesforce Analytics Cloud system. Read more about Testing Connections.

  9. Click OK to save the global connector configurations. 

  1. Ensure you have included the following namespaces in your configuration file:

    
           
                    
                 
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    
    <mule xmlns="http://www.mulesoft.org/schema/mule/core"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:sfdc-analytics="http://www.mulesoft.org/schema/mule/sfdc-analytics"
          xsi:schemaLocation="
                   http://www.mulesoft.org/schema/mule/core
                   http://www.mulesoft.org/schema/mule/core/current/mule.xsd
                   http://www.mulesoft.org/schema/mule/sfdc-analytics
                   http://www.mulesoft.org/schema/mule/sfdc-analytics/current/mule-sfdc-analytics.xsd">
     
          <!-- here goes your flows and configuration elements -->
     
    </mule>
  2. Create a global Salesforce Analytics Cloud configuration outside and above your flows, using the following global configuration code:

    
           
                    
                 
    1
    2
    3
    4
    5
    
    <sfdc-analytics:config name="Salesforce_Analytics_Cloud__Basic_authentication" username="${salesforce.username}"
                               password="${salesforce.password}" securityToken="${salesforce.securityToken}"
                               metadataFileName="${metadata.file.json.schema}"
                               metadataFileType="JSON_SCHEMA"
                               doc:name="Salesforce Analytics Cloud:Basic authentication"/>

Using the Connector

You can use the Salesforce Analytics Cloud connector as an outbound connector in your flow to push data into Salesforce Analytics Cloud system. To use it as an outbound connector, simply place the connector in your flow at any point after an inbound endpoint. Note that you can also use the Salesforce Analytics Cloud connector in a batch process to push data to Salesforce Analytics Cloud system in batches.

Use cases

The following are the common use cases for the Salesforce Analytics Cloud connector: 

  • Create a data set in the Salesforce Analytics Cloud system, upload data into the data set from an input file, and alert the system to start processing the data. 

  • Create a data set in the Salesforce Analytics Cloud system, read the data from an input file and split it into batches, upload batches of data into the data set, and alert the system to start processing the data.

Adding the Salesforce Analytics Cloud Connector to a Flow

  1. Create a new Mule project in Anypoint Studio.

  2. Drag the Salesforce Analytics Cloud connector onto the canvas, then select it to open the properties editor.

  3. Configure the connector’s parameters:

    connectorconfig

    Field Description

    Display Name

    Enter a unique label for the connector in your application.

    Connector Configuration

    Select a global Salesforce Analytics connector element from the drop-drown.

    Operation

    Select an operation for the connector to perform.

  4. Save your configurations.

Example Use Case 

Create a data set in the Salesforce Analytics Cloud system, read the data from an input file and split it into batches, upload batches of data into the data set, and alert the system to start processing the data.

Refer to documentation on Batch Processor and Data Mapper for in-depth information about these Mule elements.

demo+batch

  1. Create a Mule project in your Anypoint Studio.

  2. Drag a Batch processor into the canvas:

    image04

  3. Into the Input section of the Batch processor, drag a File connector and configure it as follows:

    image06

    Field Value

    Display Name

    Enter a name for the connector to reference it later.

    Path

    Browse to a folder where you have a csv file to upload.

    Move to Directory

    Browse to a folder where you want to write the file after it has been read.

    File Name Regex Filter

    Configure a filter to restrict the files that Mule processes.

  4. Next to the File connector, drag a Message Enricher, and then drag a Salesforce Analytics Cloud connector into it.

  5. Double-click the connector to open its Properties Editor. 

  6. If you do not have an existing Salesforce Analytics Cloud connector global element to choose, click the plus sign next to Connector Configuration.

    eglobal

  7. On the Choose Global Type window, click Salesforce Analytics Cloud: Basic Authentication.

    eglobaltype

  8. Configure the global element properties.

  9. Configure the remaining parameters of the Salesforce Analytics Cloud connector:

    create+data+set

    Field Value

    Display Name

    Enter a name for the connector instance.

    Connector Configuration

    Select the global configuration you create.

    Operation

    Create data set

    Description

    Enter a description for the data set.

    Label

    Enter a label for the data set.

    Data Set Name

    Enter a name for the data set.

  10. Double click the Message Enricher to configure it:

    MessageEnricher

    Field Value

    Display Name

    Enter a name for the Message Enricher

    Source

    #[payload]

    Target

    #[variable:dataSetId]

  11. Add another Salesforce Analytics Cloud connector in the Batch Step with the following configuration:

    2config

    Field Value

    Display Name

    Enter a name for the connector instance.

    Connector Configuration

    Select the global element you create.

    Operation

    Upload external data

    Type

    recordId

    Data Set Id:

    #[variable:dataSetId]

  12. Add a DataMapper transformer between the Message Enricher and the Batch Step.

  13. Double-click the Data Mapper to open its Properties Editor.

    image11

  14. In the Source field, select Payload - InputStream and click the edit+button(Edit) button located to the right of the Type drop down list.

  15. In the Type field select CSV

    image12

  16. Browse to the folder where you have the input csv file.

  17. Click Create Mapping.

    image13

  18. Click the name of the CSV file, then drag and drop Record:Record into the right pane. This automatically creates mapping between the corresponding fields. 

    image14

  19. Into the OnComplete section of the Batch processor, drag a Salesforce Analytics Cloud connector and configure it as follows:

    3config

    Field Value

    Display Name

    Enter a name for the connector instance.

    Connector Configuration

    Select the global element that you create for the connector.

    Operation

    Start data processing

    Data Set Id

    #[variable:dataSetId]

  20. Save and run the project as a Mule Application.

  1. Add a data-mapper:config element to your project, then configure its attributes as follows:

    
           
                   
                
    1
    2
    
    <data-mapper:config name="CSV_To_List_List_Record__" transformationGraphPath="csv_to_list_list_record__.grf"
                            doc:name="CSV_To_List_List_Record__"/>
  2. Add sfdc-analytics:config element:

    
           
                   
                
    1
    
    <sfdc-analytics:config name="Salesforce_Analytics_Cloud__Basic_authentication1" username="fh" password="fhfdhrdh" securityToken="fhfshsfdh" metadataFileName="fhsfdhfsdh" metadataFileType="sfhsfhfshfsdhsfdh" doc:name="Salesforce Analytics Cloud: Basic authentication"/>
  3. Begin the flow with a batch:job element as follows:

    
           
                   
                
    1
    
    <batch:job name="demoBatch">
  4. Inside the batch:input element, first add a file-inbound-endpoint:

    
           
                   
                
    1
    2
    3
    4
    5
    
    <batch:input>
    <file:inbound-endpoint path="D:\dev\projects\salesforce-analytics-connector\demo\src\main\resources\input" moveToDirectory="D:\dev\projects\salesforce-analytics-connector\demo\src\main\resources\processed" responseTimeout="10000"
                                       doc:name="File For Batch">
                    <file:filename-regex-filter pattern="InputDataBatch.csv" caseSensitive="true"/>
                </file:inbound-endpoint>
  5. Add a sfdc-analytics:create-data-set inside an enricher:

    
           
                   
                
    1
    2
    3
    
    <enricher source="#[payload]" target="#[variable:dataSetId]" doc:name="Message Enricher">
                    <sfdc-analytics:create-data-set config-ref="Salesforce_Analytics_Cloud__Basic_authentication1" description="Test data set" label="Test data set" dataSetName="test_data_set" doc:name="Salesforce Analytics Cloud"/>
                </enricher>
  6. Add a data-mapper:transform element and close the batch:input element

    
           
                   
                
    1
    2
    3
    
    data-mapper:transform doc:name="CSV To List<List<Record>>"
                                       config-ref="CSV_To_List_List_Record__"/>
            </batch:input>
  7. Add a batch:process-records element and inside a sfdc-analyitcs:upload-external-data element.

    
           
                   
                
    1
    2
    3
    4
    5
    6
    7
    
    <batch:process-records>
                <batch:step name="Batch_Step">
                    <sfdc-analytics:upload-external-data config-ref="Salesforce_Analytics_Cloud__Basic_authentication1" type="recordId" dataSetId="#[variable:dataSetId]" doc:name="Salesforce Analytics Cloud">
                        <sfdc-analytics:payload ref="#[payload]"/>
                    </sfdc-analytics:upload-external-data>
                </batch:step>
            </batch:process-records>
  8. Add a batch:on-complete element and a sfdc-analytics:start-data-processing element:

    
           
                   
                
    1
    2
    3
    4
    5
    6
    
    <batch:on-complete>
                <sfdc-analytics:start-data-processing config-ref="Salesforce_Analytics_Cloud__Basic_authentication1" dataSetId="#[variable:dataSetId]" doc:name="Salesforce Analytics Cloud"/>
     
            </batch:on-complete>
        </batch:job>
    </mule>
  9. Save and run the project as a Mule Application.

Example Code

For this code to work in Anypoint Studio, you must provide the credentials for the Salesforce Analytics Cloud account. You can either replace the variables with their values in the code, or you can add a file named mule.properties in the src/main/properties folder to provide the values for each variable.


         
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<mule xmlns:spring="http://www.springframework.org/schema/beans" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:batch="http://www.mulesoft.org/schema/mule/batch"
      xmlns:sfdc-analytics="http://www.mulesoft.org/schema/mule/sfdc-analytics"
      xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
      version="EE-3.6.1"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.mulesoft.org/schema/mule/sfdc-analytics http://www.mulesoft.org/schema/mule/sfdc-analytics/current/mule-sfdc-analytics.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd
http://www.mulesoft.org/schema/mule/batch http://www.mulesoft.org/schema/mule/batch/current/mule-batch.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd">
    <context:property-placeholder location="mule-app.properties"/>
    <sfdc-analytics:config name="Salesforce_Analytics_Cloud__Basic_authentication" username="${salesforce.username}"
                           password="${salesforce.password}" securityToken="${salesforce.securityToken}"
                           metadataFileName="${metadata.file.json.schema}"
                           metadataFileType="JSON_SCHEMA"
                           doc:name="Salesforce Analytics Cloud: Basic authentication"/>
     <batch:job name="demoBatch">
        <batch:input>
            <file:inbound-endpoint path="D:\dev\projects\salesforce-analytics-connector\demo\src\main\resources\input" moveToDirectory="D:\dev\projects\salesforce-analytics-connector\demo\src\main\resources\processed" responseTimeout="10000"
                                   doc:name="File For Batch">
                <file:filename-regex-filter pattern="InputDataBatch.csv" caseSensitive="true"/>
            </file:inbound-endpoint>
            <enricher source="#[payload]" target="#[variable:dataSetId]" doc:name="Message Enricher">
                <sfdc-analytics:create-data-set config-ref="Salesforce_Analytics_Cloud__Basic_authentication1" description="Test data set" label="Test data set" dataSetName="test_data_set" doc:name="Salesforce Analytics Cloud"/>
            </enricher>
            <data-mapper:transform doc:name="CSV To List&lt;List&lt;Record&gt;&gt;"
                                   config-ref="CSV_To_List_List_Record__"/>
        </batch:input>
        <batch:process-records>
            <batch:step name="Batch_Step">
                <sfdc-analytics:upload-external-data config-ref="Salesforce_Analytics_Cloud__Basic_authentication1" type="recordId" dataSetId="#[variable:dataSetId]" doc:name="Salesforce Analytics Cloud">
                    <sfdc-analytics:payload ref="#[payload]"/>
                </sfdc-analytics:upload-external-data>
            </batch:step>
        </batch:process-records>
        <batch:on-complete>
            <sfdc-analytics:start-data-processing config-ref="Salesforce_Analytics_Cloud__Basic_authentication1" dataSetId="#[variable:dataSetId]" doc:name="Salesforce Analytics Cloud"/>
 
        </batch:on-complete>
    </batch:job>
</mule>

See Also