This article explains how to perform Upsert by the Salesforce Connector with Mule 4.
1) To perform Upsert, an External ID is required on the target object (refer to Salesforce help Differences between the 'External ID' field and the 'Unique ID' field setting).
If the object does not have an External ID, please follow the below steps to create it.
1-1. Login to Salesforce
1-2. Go to Setup => Object Manager => choose target object then select [Fields & Relationships]. If there is a column with DATA TYPE "Text(xx) (External ID), you can use it. If not, click button [New] to create it.
1-3. Set Data Type as "Text" then checkbox [External ID] ON. In this example, the column name is "Ex_Account_Key". Other fields and configurations are depending on each use case, so complete the column creation.
2) Create a flow.
2-1. Set the External ID to the Upsert component.
This is a sample flow. It is using the External ID.
<flow name="upsert" doc:id="b70a6055-8130-4a2e-a2cf-199a83e7d86e" >
<http:listener doc:name="Listener" doc:id="f6848dac-9cbc-4b7c-8ae8-d20c8f54a08d" config-ref="HTTP_Listener_config" path="/upsert"/>
<ee:transform doc:name="Transform Message" doc:id="acbc26ad-4b77-4c4d-ab29-dc5e2685d4bf" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
[{
Id: payload.Id,
Ex_Account_Key__c: payload.Ex_Account_Key__c,
Name: payload.Name,
NumberOfEmployees: payload.NumberOfEmployees
}]]]></ee:set-payload>
</ee:message>
</ee:transform>
<salesforce:upsert type="Account" doc:name="Upsert" doc:id="54421550-ca61-4099-bf79-fddd602a875d" config-ref="Salesforce_Config" externalIdFieldName="Ex_Account_Key__c"/>
<ee:transform doc:name="Transform Message" doc:id="31a93d48-7d08-4ff6-95b4-9472cbfb9009" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload map {
id:$.id,
errors:$.errors,
success:$.success
}]]></ee:set-payload>
</ee:message>
</ee:transform>
</flow>
$ curl -X POST 'http://localhost:8081/upsert' \
-H 'Content-type: application/json' \
--data '{"Ex_Account_Key__c":"ext2", "Name": "Name3", "NumberOfEmployees": 100}'
[
{
"id": "0012v00002lP6tSAAS",
"errors": [
],
"success": true
}
]
001116916

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.