MuleSoft Technical Guides

Mule 4 connectors for Salesforce

User MuleSoft Integration Team
Calendar September 29, 2021

Anypoint Connector for Salesforce (Salesforce Connector) enables us to create apps that react to Salesforce events such as adding, changing, or deleting objects, topics, documents, and channels. Salesforce Connector enables us to connect to the Salesforce APIs.

In this blog we will dive into usage, configuration and output parameters of 5 most useful connectors.

1. Create Job Bulk API v2:

Uploading records stored in the CSV format to Salesforce is one the most common use cases MuleSoft Customers use. Among the many ways to fulful this functionality, dataloader.io is the most common data loader on Salesforce AppExchange along with Anypoint’s Salesforce connector with various operations.

Usage: With Create job bulk API v2 we can upload our records stored in CSV format to Salesforce. We can drag and drop the connector, and further configure it.

Input Parameters:  We need to pass the Salesforce object name and external id.

Example:

demoSalesforce:  

type: "Demo_Salesforce__c"

externalId: "External_Key__c"

[Payload should be of CSV type]

Example:

External_Key__c,Account_Id__r
xyz1234,ACC1234

Create Bulk JOB API

Connector Configuration:

Create bulk job API 2

Output Parameters:

The result of get job bulk state v2 in JSON format

{
  "lineEnding": "LF",
  "numberRecordsFailed": 0,
  "externalIdFieldName": "External_Key__c",
  "numberRecordsProcessed": 0,
  "systemModstamp": "2021-09-08T12:22:31.000+0000",
  "errorMessage": null,
  "apiActiveProcessingTime": 0,
  "concurrencyMode": "Parallel",
  "retries": 0,
  "apexProcessingTime": 0,
  "createdDate": "2021-09-08T12:22:30.000+0000",
  "apiVersion": "50.0",
  "id": "75p0000XhzGAS",
  "state": "InProgress",
  "totalProcessingTime": 0,
  "jobType": "V2Ingest",
  "operation": "upsert",
  "contentType": "CSV",
  "createdById": "002w0008reAC",
  "columnDelimiter": "COMMA",
  "object": "Demo_Salesforce__c"
}

 

2. Get job state bulk api v2 

In Salesforce, we only have a job id. If we want a detailed job status, we need to use workbench and query.

Get Job ID connector

Usage: Get Job state bulk api v 2 is a connector we use to get the job status of a bulk upsert  job id. It provides us detailed results in a JSON format.

Input Parameters: We need to provide a Job Id. Ex. 750p0000007X7ze

Bulk Job Flow

Connector Configuration:

job state bulk api

Output Parameters: The result of get job bulk state v2 in JSON format

 {
  "lineEnding": "LF",
  "numberRecordsFailed": 0,
  "externalIdFieldName": "External_Key__c",
  "numberRecordsProcessed": 1,
  "systemModstamp": "2021-09-08T12:22:33.000+0000",
  "errorMessage": null,
  "apiActiveProcessingTime": 177,
  "concurrencyMode": "Parallel",
  "apexProcessingTime": 0,
  "retries": 0,
  "createdDate": "2021-09-08T12:22:30.000+0000",
  "apiVersion": "50.0",
  "state": "JobComplete",
  "id": "75p0007hzGAS",
  "totalProcessingTime": 250,
  "jobType": "V2Ingest",
  "operation": "upsert",
  "contentType": "CSV",
  "createdById": "005w0008FreAC",
  "columnDelimiter": "COMMA",
  "object": "Demo_Salesforce__c"
}

 

3. Query:

Usage: Query is a connector which is similar to db query but this connector we use to execute salesforce query(SOQL). We use a query connector to get the details of the salesforce object and configure the listener to trigger the request.

Input Parameters: The SOQL query to retrieve the records

Example:

Account_Id_Salesforce__c, Demo_Salesforce_Id__c FROM Demo_Salesforce__c

Query/ Salesforce Connector/Flow

Connector Configuration:

connector configuration

Output Parameters: Result of the SOQL Query in JSON format.

[
  {
    "Account_Id_Salesforce__c": XYZ123,
    "Demo_Salesforce_Id__c": 67.0
  },
  {
    "Account_Id_Salesforce__c": "12JK345",
    "Demo_Salesforce_Id__c": 34.0
  },
  {
    "Account_Id_Salesforce__c": "12NJ455",
    "Demo_Salesforce_Id__c": "45.0"
  },
  {
    "Account_Id_Salesforce__c": "12BB455",
    "Demo_Salesforce_Id__c": "43.0"
  },
  {
    "Account_Id_Salesforce__c": "12RF55",
    "Demo_Salesforce_Id__c": "48.0"
  }
]

 

4. Upsert

Usage: In upsert operation, Salesforce internally validates the data based on Object’s Id or External ID. So, upsert takes a little bit longer time than insert or update. Using the upsert operation, we can either insert or update an existing record in one call.

Input Parameters:  We need to pass the Salesforce object name and external id. 

Example:

demoSalesforce:  

type: "Demo_Salesforce__c"

externalId: "External_Key__c"

Payload’s mime type is java.

Example:

[
{
"Demo_Id__r": {
"Demo_Number__c": "143",
"type": "Demo_Header__c"
},
"Demo_Line_Item_Id__c": "143-1",
"Site_Name__c": "DemoS1",
"Product__r": {
"Product_Id__c": "\ABCXY767",
"type": "Product2"
},
"Speed__c": "UC",
"Contract_Terms__c": "ContractTerms",
"Request_Types__c": "New Provision",
"Quantity__c": "5",
"Billing_OTC__c": "2",
"Billing_RC__c": "4",
"CurrencyIsoCode": "SGD"
}
]

Upsert Salesforce

Connector Configuration: 

Upsert Salesforce

Output Parameters: The result of upsert in JSON format.

{
"id": null,
"items": [
{
"exception": null,
"message": null,
"payload": {
"created": false,
"success": true,
"id": "a10000zOPQEA2",
"errors": [
]
},
"id": "a1p000PQEA2",
"successful": true,
"statusCode": null
}
],
"successful": true
}

 

5. Update

Usage: In update operation, Salesforce internally validates the data based on
Object’s Id. Update the corresponding Salesforce object with the new values.

Input Parameters: We need to pass the Salesforce object name.

demoSalesforce:
type: "Demo_Salesforce__c"

Payload in JSON Format
Example:

[
{
"External_Key__c": "_ACCUEN1414091|55789|202108",
"service_no__c": "55789",
"demo__c": "23",
"service__c": "#N/A",
"month_yyyymm__c": "202108",
"Id": "a12p000nAG"
}
]

Upsert_Mule_Salesforce_Connectors

Connector Configuration:

Upsert Connector Configuration

Output Parameters: The result of upsert in JSON format

{
"id": null,
"items": [
{
"exception": null,
"message": null,
"payload": {
"success": true,
"id": "a1200EAAG",
"errors": [
]
},
"id": "a10003SAG",
"successful": true,
"statusCode": null
}
],
"successful": true
}

 

 

Leave a comment

Your email address will not be published. Required fields are marked *