Loading

Salesforce Connector | How to Set One or More Fields of an Object to Null Using Update or Upsert Operation

Дата публикации: Aug 1, 2025
Задача

GOAL

To set one or more fields of an object to null using the Update or Upsert operation of Salesforce Connector
Действия

In Salesforce Connector version 9.11.0 or earlier

You will find it under "Global Elements" tab -> double click on the "Salesforce Config" -> "General" tab -> "Advanced" Section -> "Can Clear Fields by Updating Field to Null" dropdown and select True.

In Salesforce Connector version 10.0.0 or later

The functionality that existed above is now only available for Apex calls when enabling "Global Elements" tab -> double click on the "Salesforce Config" -> "Apex" tab -> "Include Null Values = true"

Otherwise, if you leave it unchecked when using the "Invoke apex rest method" or "Invoke apex soap method" operation, or if you are using the Update or Upsert operation, you should modify your DataWeave Transform to make use of "fieldsToNull".

For example:

..
"FirstName": null,
(fieldsToNull: ["FirstName"]) if (payload.FirstName == null)

How to add more than one field to the fieldsToNull array using DataWeave?

You can use the following transformation as a sample:
%dw 2.0
output application/json
import * from dw::core::Objects
---
[{
	Id: '000012345',
	FirstName: payload.FirstName__c,
	MiddleName: payload.MiddleName__c,
	LastName: payload.LastName__c,
	Company: payload.Company__c,
    Email: payload.Email__c,
   ( fieldsToNull: valueSet(payload mapObject (( key: $$ ) if(($ == null) or (isEmpty($)))  )))
}]
User-added image
Don't forget to import the needed libraries from dw::core::Objects


NOTE: If the output attributes will keep the same keys you can use this minimal transformation:
%dw 2.0
output application/json
import * from dw::core::Objects
---
payload mapObject ((($$): $) if ($ != null)) ++
    "fieldsToNull": valueSet(payload mapObject (( key: $$ ) if(($ == null) or (isEmpty($))) )  )

User-added image

NOTE: The function valueSet has been deprecated and instead of that valuesOf function is introduced starting from DW 2.3.0. It is supported by Mule 4.3 and later.

Disclaimer: This solution provides a suggestion that should be considered in conjunction with your specific use case and requirements and does not represent a complete solution for all circumstances.
Номер статьи базы знаний

001116929

 
Загрузка
Salesforce Help | Article