DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Handle HL7 MLLP Messages With Mule 4
  • Implementing NetSuite Saved Search With MuleSoft - Part 1
  • MuleSoft OAuth 2.0 Provider: Password Grant Type
  • Exploring API Headers

Trending

  • IoT and Cybersecurity: Addressing Data Privacy and Security Challenges
  • Endpoint Security Controls: Designing a Secure Endpoint Architecture, Part 2
  • Designing a Java Connector for Software Integrations
  • Unit Testing Large Codebases: Principles, Practices, and C++ Examples
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Understanding Salesforce Composite Connector With MuleSoft

Understanding Salesforce Composite Connector With MuleSoft

Salesforce Composite Connector provides various benefits like simplifying the code, reduce the network overhead by avoiding round trip between MuleSoft and Salesforce, Improve Application performance.

By 
Jitendra Bafna user avatar
Jitendra Bafna
DZone Core CORE ·
Updated Apr. 11, 21 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
26.1K Views

Join the DZone community and get the full member experience.

Join For Free

This article will talk about the Salesforce Composite Connector and what are the various operations provided by the Salesforce Composite Connector. It will also talks about what are the different authentication mechanism supported to connect Salesforce and how to configure it.

Salesforce Composite Connector enable you to access various resources, objects or services in the Salesforce using the single API call. It is Anypoint Connector which allows you to use the Salesforce Composite Batch, Request and sObject tree api's.

It provides various benefits like simplifying the code, reduce the network overhead by avoiding round trip between MuleSoft and Salesforce, Improve Application performance.

This connector supports various Authentication mechanism are listed below.

  • OAuth v2.0
  • OAuth SAML
  • OAuth JWT
  • OAuth Username and Password 

By default, Salesforce Composite Connector is not part of the Mule Palette, so you can  installed from the Anypoint Exchange.

Here is the step by step video explaining how to configure the Authentication and installed the connector in the Mule palette.


Composite Request

Composite Request perform series of the rest api's call in single request. You can always use the  output of the one request as the input to the subsequent request. Requests in the composite call is known as subrequests. You can have up to 25 subrequest in single call.

It provides a single response which includes all subrequest responses. Top level request always returns HTTP Status Code as "200".

In below request body, there is the 2 subrequests. The first creates the Account in the salesforce and assigned output to the refAccount. The second creates the contact under the new parent Account by referencing the refAccount in the body.

Request Body

JSON
 




xxxxxxxxxx
1
16


 
1
{
2
"compositeRequest" : [{
3
  "method" : "POST",
4
  "url" : "/services/data/v51.0/sobjects/Account",
5
  "referenceId" : "refAccount",
6
  "body" : { "Name" : "Jack John" }
7
  },{
8
  "method" : "POST",
9
  "url" : "/services/data/v51.0/sobjects/Contact",
10
  "referenceId" : "refContact",
11
  "body" : { 
12
    "LastName" : "John",
13
    "AccountId" : "@{refAccount.id}"
14
    }
15
  }]
16
}


Response Body

JSON
 




xxxxxxxxxx
1
16


 
1
{
2
"compositeRequest" : [{
3
  "method" : "POST",
4
  "url" : "/services/data/v51.0/sobjects/Account",
5
  "referenceId" : "refAccount",
6
  "body" : { "Name" : "Jack John" }
7
  },{
8
  "method" : "POST",
9
  "url" : "/services/data/v51.0/sobjects/Contact",
10
  "referenceId" : "refContact",
11
  "body" : { 
12
    "LastName" : "John",
13
    "AccountId" : "@{refAccount.id}"
14
    }
15
  }]
16
}


Here is the video tutorial explaining how to configure the Composite Request.


It also support the Transaction by using attribute allOrNone. By default allorNone is false, in case if you want to enable the transaction, you can add allOrNone attribute to true in he request body. This will ensure either all subrequest process successfully or nothing will be committed in case of single or multiple failures.

JSON
 




xxxxxxxxxx
1
16


 
1
{
2
"allOrNone": true
3
"compositeRequest" : [{
4
  "method" : "POST",
5
  "url" : "/services/data/v51.0/sobjects/Account",
6
  "referenceId" : "refAccount",
7
  "body" : { "Name" : "Jack John" }
8
  },{
9
  "method" : "POST",
10
  "url" : "/services/data/v51.0/sobjects/Contact",
11
  "referenceId" : "refContact",
12
  "body" : { 
13
    "LastName" : "John",
14
    "AccountId" : "@{refAccount.id}"
15
    }
16
  }]
17
}


Here is video tutorial explaining how to configure the Composite Request with Transaction.


Composite Batch

Composite Batch allows you to perform up to 25 independent subrequest in the single call. All the subrequests count against the rate limit. The response bodies and HTTP statuses of the subrequests in the batch are returned in a single response body.

Batching for the following resources and resource groups is available in API version 34.0 and later.

  • Limits—vXX.X/limits
  • sObject resources—vXX.X/sobjects/
  • Query—vXX.X/query/?q=soql
  • QueryAll—vXX.X/queryAll/?q=soql
  • Search—vXX.X/search/?q=sosl
  • Connect resources—vXX.X/connect/
  • Chatter resources—vXX.X/chatter/

In below request body, there are the 3 subrequests. The first is updating the name in the Account objects. The second is fetching the particular account Name and Billing Postal Code. The third request is sending query to retrieve Id and Name for particular account.

Request Body

JSON
 




xxxxxxxxxx
1
19


 
1
{
2
    "batchRequests": [
3
        {
4
            "method": "PATCH",
5
            "url": "v51.0/sobjects/account/0013B00000iP47yQAC",
6
            "richInput": {
7
                "Name": "John Jim"
8
            }
9
        },
10
        {
11
            "method": "GET",
12
            "url": "v51.0/sobjects/account/0013B00000iP47yQAC?fields=Name,BillingPostalCode"
13
        },
14
        {
15
            "method": "GET",
16
            "url": "v51.0/query?q=Select Id,Name from Account Where Id='0013B00000iP47yQAC'"
17
        }
18
    ]
19
}


Response Body

JSON
 




xxxxxxxxxx
1
38


 
1
{
2
    "hasErrors": false,
3
    "results": [
4
        {
5
            "statusCode": 204,
6
            "result": null
7
        },
8
        {
9
            "statusCode": 200,
10
            "result": {
11
                "attributes": {
12
                    "type": "Account",
13
                    "url": "/services/data/v51.0/sobjects/Account/0013B00000iP47yQAC"
14
                },
15
                "Name": "John Jim",
16
                "BillingPostalCode": null,
17
                "Id": "0013B00000iP47yQAC"
18
            }
19
        },
20
        {
21
            "statusCode": 200,
22
            "result": {
23
                "totalSize": 1,
24
                "done": true,
25
                "records": [
26
                    {
27
                        "attributes": {
28
                            "type": "Account",
29
                            "url": "/services/data/v51.0/sobjects/Account/0013B00000iP47yQAC"
30
                        },
31
                        "Id": "0013B00000iP47yQAC",
32
                        "Name": "John Jim"
33
                    }
34
                ]
35
            }
36
        }
37
    ]
38
}


Here is the video tutorial explaining how to configure the Composite Batch.

sObject Tree

sObject tree creates one or more sObject trees with root record of the specified type. It is the collection of parent-child, netsed with a single record type. There are few limitations with sObject tree as it allows only 200 records across all the trees, allows up to 5 records of different type and and it is up to 5 level deep.

In below request body, there are 2 account creation request with 2 contact for each account.

Request Body

JSON
 




xxxxxxxxxx
1
39


 
1
{
2
"records" :[{
3
    "attributes" : {"type" : "Account", "referenceId" : "ref1"},
4
    "name" : "Jit John",
5
    "phone" : "1234567890",
6
    "Contacts" : {
7
      "records" : [{
8
         "attributes" : {"type" : "Contact", "referenceId" : "ref2"},
9
         "lastname" : "Smith",
10
         "Test1__c": "test123",
11
         "email" : "sample@salesforce.com"
12
         },{         
13
         "attributes" : {"type" : "Contact", "referenceId" : "ref3"},
14
         "lastname" : "Evans",
15
         "Test1__c": "test123",
16
         "email" : "sample@salesforce.com"
17
         }]
18
      }
19
    },
20
{
21
    "attributes" : {"type" : "Account", "referenceId" : "ref4"},
22
    "name" : "Jim John",
23
    "phone" : "1234567890",
24
    "Contacts" : {
25
      "records" : [{
26
         "attributes" : {"type" : "Contact", "referenceId" : "ref5"},
27
         "lastname" : "Jack",
28
         "Test1__c": "test123",
29
         "email" : "sample@salesforce.com"
30
         },{         
31
         "attributes" : {"type" : "Contact", "referenceId" : "ref6"},
32
         "lastname" : "Jin",
33
         "Test1__c": "test123",
34
         "email" : "sample@salesforce.com"
35
         }]
36
}
37

          
38
     }]
39
}


Response Body

JSON
 




xxxxxxxxxx
1
29


 
1
{
2
    "hasErrors": false,
3
    "results": [
4
        {
5
            "referenceId": "ref1",
6
            "id": "0013B00000iP49fQAC"
7
        },
8
        {
9
            "referenceId": "ref4",
10
            "id": "0013B00000iP49gQAC"
11
        },
12
        {
13
            "referenceId": "ref2",
14
            "id": "0033B00000boceSQAQ"
15
        },
16
        {
17
            "referenceId": "ref3",
18
            "id": "0033B00000boceTQAQ"
19
        },
20
        {
21
            "referenceId": "ref5",
22
            "id": "0033B00000boceUQAQ"
23
        },
24
        {
25
            "referenceId": "ref6",
26
            "id": "0033B00000boceVQAQ"
27
        }
28
    ]
29
}


Here is the video tutorial explaining how to configure the sObject Tree.


References

https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_composite_composite.htm

https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_composite_batch.htm

https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_composite_sobject_tree.htm

https://docs.mulesoft.com/salesforce-composite-connector/2.8/

Conclusion

Salesforce Composite Connector is Anypoint Connector which reducing the multiple calls towards Salesforce, avoiding round tripping between MuleSoft and Salesforce, simplifying the code as you don't have to orchestrate the multiple calls towards Salesforce and improve the performance of your applications. 

Connector (mathematics) Requests MuleSoft authentication

Opinions expressed by DZone contributors are their own.

Related

  • Handle HL7 MLLP Messages With Mule 4
  • Implementing NetSuite Saved Search With MuleSoft - Part 1
  • MuleSoft OAuth 2.0 Provider: Password Grant Type
  • Exploring API Headers

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!