function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Charlie BratchesCharlie Bratches 

ForceClient Insert/Update null values

I am trying to update a custom date field to a null value using ForceClient in .NET. Currently, it doesn't seem like it's possible to do this, even on optional Date fields. I've double-checked that the field is not required.

The way I understand it is, a Date field can accept a valid date string or null. But passing null causes the field not to update, it doesn't actually null out the field.

Code is something like this:
using (ForceClient sfClient = GetSfClient())
{
    SuccessResponse resp = null;
    try
    {
    	accountData.CustomDateField = null;
        resp = await sfClient.UpdateAsync("Account", accountId, accountData);
    }
    ...
}
"accountData" is an object containing all the fields we're updating on the account. Like I mentioned above, passing null for any of those fields just causes the field to not update. For a Date field, we get an error on anything besides a valid date format. So I've tried passing "null", empty string, white space, etc.

How can I null out a Date field, or any field for that matter?

Thank you for your help,
Charlie Bratches


 
MagulanDuraipandianMagulanDuraipandian
Use fieldsToNull to make it as null.
Sample Code - https://www.infallibletechie.com/2020/01/fieldstonull-in-salesforce-api-call.html
Charlie BratchesCharlie Bratches
MagulanDuraipandian - thanks for your response.

As per the example in the link you posted, I'm not able to instantiate an sObject using the Salesforce .Force assembly. Perhaps I'm missing a .dll file? 

In the example code I posted, the "accountData" is a custom object we use to map our data to our custom fields.
I tried a solution like this:
using (ForceClient sfClient = GetSfClient())
{
    SuccessResponse resp = null;
    try
    {
    	accountData.CustomDateField = null;
    	accountData.fieldsToNull = new string[]{"my_custom_date_field__c"};
        resp = await sfClient.UpdateAsync("Account", accountId, accountData);
    }
    ...
}

When I add a string[] property to my accountData object called fieldsToNull and populate it with the name of my custom date field, I get the following error: 

"No such column 'fieldsToNull' on sobject of type Account."

What am I missing? Any further help would be appreciated.
MagulanDuraipandianMagulanDuraipandian
Check the example in the link. I think accountData in your example is the instance of Account instead of sObject.
Stephen WondStephen Wond
Charlie, did you get anywhere with this? I seem to be facing the same problem and there is little to no guidance out there.