Salesforce Fields Not Updating With C# Web Service

Rachel Soderberg - May 10 '19 - - Dev Community

This week I made a silly discovery while I built out some new functionality for the Salesforce Asset Updater application I've been assigned to create at work. I'm hoping that by sharing this discovery here, I can save someone else the time sink of trying to figure out why their fields won't update!

Salesforce has a number of different field types that can be used on each object. These range from the simplest text type fields all the way up to more complex lookup fields with relationships to other objects. Non-text fields such as Number, Checkbox, Date, and Picklist require a very simple but essential extra step during object initialization to indicate to Salesforce that a change must be made to these fields.

As a reminder, typical Salesforce object initialization for update and creation with only string fields looks like:

Account newAccount = new Account{
    Id = GetSalesforceId(custName),
    Phone_Number__c = custPhone,
    Shipping_Address__c = custAddress,
}

Once you attempt to create or update fields that are of a non-string type (such as a Checkbox), you must provide the desired field value and also update the field's "specified" field as seen in the example below:

Account newAccount = new Account{
    Id = GetSalesforceId(custName),
    Phone_Number__c = custPhone,
    Shipping_Address__c = custAddress,
    /*Updating Checkbox field below*/
    Is_Premium_Customer__c = true,
    Is_Premium_Customer__cSpecified = true
}

There is no clear exception or error output letting you know you've forgotten this crucial step. The only indication that you've attempted to modify one of these special fields without including the specified field is the field just refusing to update without any complaints. Personally, I spent almost an hour trying to figure out where I went wrong before the right google search finally led me down a path to this solution.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .