Blog

Working with Salesforce sObjects with Composite Connector Part II

Sivendu SasidharanWritten by Sivendu Sasidharan

In our previous blog ' Working with Salesforce sObjects with Composite Connector Part 1', we looked at some common sObject type names in Apex used for standard objects. In this blog, we will look more into this MuleSoft Salesforce Integration focusing on Collections, what a sObject collection in Salesforce is and what it does?

What is an SObject Collection in Salesforce ?

Collections in Apex can be lists, sets, or maps.

Lists

A list is an ordered collection of elements that are distinguished by their indices. List elements can be of any data type—primitive types, collections, sObjects, user-defined types, and built-in Apex types.

Sets

A set is an unordered collection of elements that do not contain any duplicates. Set elements can be of any data type—primitive types, collections, sObjects, user-defined types, and built-in Apex types.

Maps

A map is a collection of key-value pairs where each unique key maps to a single value. Keys and values can be any data type—primitive types, collections, sObjects, user-defined types, and built-in Apex types.

Parameterized Typing

Apex, in general, is a statically-typed programming language, which means users must specify the data type for a variable before that variable can be used.tions in Apex can be lists, sets, or maps.

Working with SObject Tree using composite connector

  • Executes actions on multiple records in one request.
  • Reduces the number of round-trips between the client and server.
  • The response bodies and HTTP statuses of the requests are returned in a single response body.
  • The entire request counts as a single call toward your API limits.
  • It allows up to 200 records to be created, updated, retrieved, or deleted with fewer round-trips.
  • We can determine if the entire request should be rolled back in case of an error.
  • Objects are created in the order they’re listed
  • If the request body includes objects of more than one type, they are processed as chunks. For example, if the incoming objects are {account1, account2, contact1, account3}, the request is processed in three chunks: . A single request can process up to 10 chunks.

Request Parameters

  • allOrNone : - Optional. Default is false - Indicates whether to roll back the entire request when the creation of any object fails (true) or to continue with the independent creation of other objects in the request
  • records: - Required - List of sObjects. - The list can contain up to 200 object

Request Example

{
    "allOrNone": true,
    "records":
    [
        {
            "attributes":
            {
                "type": "Account"
            },
            "Name": "Example Account",
            "BillingCity": "San Francisco",
            "Phone": "232786764"
        },
        {
            "attributes":
            {
                "type": "Contact"
            },
            "Email": "example@gamil.com",
            "FirstName": "Anice",
            "LastName": "John"
        }
    ]
}

Response Example - Success

[
    {
        "id": "0012x00000ELhyJAAT",
        "success": true,
        "errors":
        []
    },
    {
        "id": "0032x00000AKPKBAA5",
        "success": true,
        "errors":
        []
    }
]