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
mh1974mh1974 

Cannot set date field to null through Enterprise WSDL

I'm writing a piece of C# code to reset a date field after a set time period has elapsed,  here's a demo of the code:

 

AccountObject.MyDate__c =  null;

AccountObject.MyDate__cSpecified = true;

 

However,  when I run the update,  nothing happens.  If I assign a date,  I get a result.  I can manually update the record and remove the date,  so,  why can't I do this through code?

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell
You have to use the fieldsToNull property.

All Answers

SuperfellSuperfell
You have to use the fieldsToNull property.
This was selected as the best answer
mh1974mh1974

By Jove I think he's got it!  Here's what I did:

 

AccountObject.MyDate__c = null;

AccountObject.MyDate__cSpecified = true;

AccountObject.fieldsToNull = new string[1] { "MyDate__c" };

 

You still need to set field to null otherwise you get an error along the lines of,

 

"A duplicate value was specified for field 'MyDate__c' in object 'Account', duplicate value 'Thu Oct 01 00:00:00 GMT 2009' prior value '' (prior value could have been set to '' with 'fieldsToNull')"