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

Issues updating Lead using API

I'm trying to update a custom field for a Lead. However, the field isn't updating. I'm not quite sure if I'm trying to update the Lead correctly.

Lead updateThisLead = new Lead();

updateThisLead.Id = idOfLeadToUpdate;
updateThisLead.UpdateThisField__c = "Updated value";

SforceService sfdc = new SforceService();
string usr = "xxxxxxx";
string pwd = "xxxxxxx";

LoginResult lr = sfdc.login(usr, pwd);

sfdc.Url = lr.serverUrl;

sfdc.SessionHeaderValue = new sforce.SessionHeader();
sfdc.SessionHeaderValue.sessionId = lr.sessionId;
sforce.GetUserInfoResult userInfo = lr.userInfo;

sObject[] records = new sObject[] { updateThisLead };
SaveResult[] sr = sfdc.update(records);

Check sr[0].errors to see if there are any errors in there.  Or just put a breakpoint on that update statement and use the debugger to see the errors.  Remember, to, that in .net some types of field require you to set the Specified flag.



Are you sure that your custom field is not updated. Maybe after updating when you get Lead object your custom field 

is undefined (i mean this custom field doesn't read from database). See which field do you get within your query, check fields in the select statement




There really isn't enough information provided to give you the specific answer to your problem. Salesforce has some special cases to consider when updating specific datatypes.


When updating Boolean values you should take the following approach:


      lead.<Custom Field Name>__c = customValue

      lead.<Custom Field Name>__cSpecified = true


Salesforce will provide these "Specified" fields for the object on a data type basis in the API. If a "Specified" field is set to "true" then it will update the Field that it is associated with. This is also the case with other datatypes, such as: Date, Integer.... etc...


Hope this helps,