Andre's Blog

Personal blog of Andre Perusse

Fields Not Updating When Using Salesforce API with .NET / C#

I just spent the last few hours tearing my hair out trying to determine why a Contact record in Salesforce wasn't being updated from their API. I had successfully created the record using Visual Studio to generate a series of proxy classes from Salesforce's WSDL file, but subsequent updates didn't appear to be working at all even though the API reported a successful update transaction.

It turns out that all the fields I was trying to update were non-string fields. A few of them were Boolean fields (true/false), some were number fields, and others were date fields. Apparently, when using .NET, you have to explicitly tell Salesforce that you've changed the value of any non-string field by using the associated "Specified" field, like so:

myContactRecord.CustomDateField__c = DateTime.Now;
myContactRecord.CustomDateField__cSpecified = true;

A thousand thank-you's to fine fellow (RobD) who answered this question on StackOverflow.