Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update not working in SalesForce API

Tags:

c#

api

salesforce

I'm trying to update a record via the SalesForce API (Enterprise WSDL).

The code below executes fine, and the saveResult returned says that the operation was successful.

Yet, when I look in SalesForce - the record has not been updated. The only thing that I can think of is that I am using the wrong Id - But I have quintuple checked this and checked it again and then re-checked it.

Has anybody encountered something like this before? Alternatively, I will be so pleased if someone can point out the stupid mistake that I've probably made somewhere :-)

sforce.Participant__c updateParticipant = new sforce.Participant__c();

        updateParticipant.Id = participant.Id.Length == 15? participant.Id : participant.Id.Substring(0, 15);

        if (updateType == "pre")
        {
            updateParticipant.Manual_Download_Date__c = DateTime.Now;
            updateParticipant.Manual_Download__c = true;
        }
        else if (updateType == "post")
        {
            updateParticipant.Post_Class_Manual_Download__c = true;
            updateParticipant.Post_Class_Manual_Downloaded_Date__c = DateTime.Now;
        }

        sforce.SaveResult[] result = SFLib.sfdc.update(new sforce.sObject[] { updateParticipant });
        if (result == null || result.Length <= 0)
            return false;
        else
        {
            if (result[0].success == true)
                return true;
            else
                throw new Exception("Update participant failed", new Exception(result[0].errors[0].message));
        }
like image 378
RobD Avatar asked Mar 01 '12 14:03

RobD


People also ask

How do you update a record in Salesforce using REST API?

You use the sObject Rows resource to update records. Provide the updated record information in your request data and use the PATCH method of the resource with a specific record ID to update that record. Records in a single file must be of the same object type.

How do you update data in API?

The API works the same way as the initial call for saving the object. To update a property value, simply modify it in the instance representing the saved object. The example below retrieves a saved object, modifies the “name” property, and saves it back in the data store.


1 Answers

When using .Net to call the Update method on the API, you need to set the *fieldname__cSpecified* field explicitly. E.g.

updateParticipant.aDateField_StartDate__c = DateTime.Now;
updateParticipant.aDateField_StartDate__cSpecified = true;
like image 82
RobD Avatar answered Oct 03 '22 18:10

RobD