How to implement sObject Tree in MuleSoft Composite Connector?

on

|

views

and

comments

Hello #Muleys #Trailblazers,

In our previous blog post, we have seen how to configure MuleSoft Composer in MuleSoft AnyPoint Studio. If you missed this Here is the Link for you.

Working with SObjectTree

  • HTTP ListenerAccepts data from HTTP requests
  • Transform MessageTransforms the HTTP input
  • Create sobject tree Connects with Salesforce and creates an SObject tree

Step1 – Create a Mule Project

In Studio, create a new Mule project in which to add and configure the connector:

  1. Select File > New > Mule Project.
  2. Enter a name for your Mule project and click Finish.

Step2 – Configure a Source

A source initiates a flow when a specified condition is met. You can configure one of these sources to use with Salesforce Composite Connector: For the demo, we are going to Use HTTP Listener

  1. HTTP Listener – Initiates a flow each time it receives a request on the configured host and port

For example, to configure an HTTP listener, follow these steps:

  1. In the Mule Palette view, select HTTP > Listener.
  2. Drag Listener to the Studio canvas.
  3. On the Listener configuration screen, optionally change the value of the Display Name field.
  4. Specify a value for the Path field.
  5. Click the plus sign (+) next to Connector configuration to configure a global element that can be used by all instances of HTTP Listener in the app.
  6. On the General tab, specify connection information for the connector.
  7. Click Test Connection to confirm that Mule can connect with the specified server.
  8. Click OK.
  9. Refer below images

Step3 – Add a Composite Connector Operation to the Flow

To add an operation for Salesforce Composite Connector, follow these steps:

  1. In the Mule Palette view, select Salesforce Composite and then select the create sobject tree operation.
  2. Drag the operation onto the Studio canvas to the right of the input source.
  3. Click the plus sign (+) next to Connector configuration to configure a global element that can be used by all instances of Salesforce Composite in the app.
  4. Select “OAuth JWT” for connection. To configure visit “How to Authenticate Salesforce using JWT from Mulesoft”
  5. On the General tab, specify connection information for the connector.
  6. Click Test Connection to confirm that Mule can connect with the specified server.
  7. In the Create sobject tree properties window, enter Account in the SObject Root Type field
  8. Click OK.

In the demo, we are going to create an Account record and Multiple Contact Records related to that Account & An Opportunity Record related to that Account as well using a Single Request. Here is what MuleSoft Composite Connector can do.

  • Used for creating one or more SObject trees having root records of the specified type.
  • SObject Tree is a collection of nested, parent-child records with a single root record.
  • In the request, we should provide the type and reference ID of each record

Here is the Request that we are going to use for the demo

Request Body

The request body contains a records collection that includes sObject trees. Each record will have following properties

  • Attributes:  Indicate attribute of a particular record Has two sub-properties
    • objectType: record’s type (example: Account)
    • referenceId: Reference ID for this record. Must be unique in the context of the request and start with an alphanumeric character.
  • Object fields: Field and value for this record
  • Child Relationships: Indicate child relationship of this record, for example
    • Contacts
    • Opportunities
    • Cases
    • For Any Custom Child Object Use RelationShip Name Like Invoices__r

The request can contain the following:

  1. Up to a total of 200 records across all trees
  2. Up to five records of different types
  3. SObject trees up to five levels deep

Transform Message

The Transform Message component uses input data to transform the HTTP input for the following Create operation.

Here is the code for the same

Response Body

  1. hasErrors: true if an error occurred while creating a record; false otherwise
  2. results:
    • Contains reference ID and new record ID of each record if success
    • Contains only the reference ID of the record that caused the error, error status code, error message, and fields related to the error if there are any failures

Working Demo

Project XML File

Developer Resource

Happy Learning

 

Amit Singh
Amit Singhhttps://www.pantherschools.com/
Amit Singh aka @sfdcpanther/pantherschools, a Salesforce Technical Architect, Consultant with over 8+ years of experience in Salesforce technology. 21x Certified. Blogger, Speaker, and Instructor. DevSecOps Champion
Share this

Leave a review

Excellent

SUBSCRIBE-US

Book a 1:1 Call

Must-read

How to Utilize Salesforce CLI sf (v2)

The Salesforce CLI is not just a tool; it’s the cornerstone of development on the Salesforce Platform. It’s your go-to for building, testing, deploying, and more. As one of the most important development tools in our ecosystem

Save the day of a Developer with Apex Log Analyzer

Table of Contents What is Apex Log Analyzer? Apex Log Analyzer, a tool designed with Salesforce developers in mind, is here to simplify and accelerate your...

Salesforce PodCast

Introduction Hey Everyone, Welcome to my podcast, the first-ever podcast in India for Salesforce professionals. Achievement We are happy to announce that we have been selected as Top...

Recent articles

More like this

LEAVE A REPLY

Please enter your comment!
Please enter your name here

5/5

Stuck in coding limbo?

Our courses unlock your tech potential