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
calvin_nrcalvin_nr 

Updating custom object records using C# and force API is not working.

Hi folks,

 

My code for updating records of a custom object is not working as expected. 

 

I thought we would just need to create an object of the same type and assign the id of the record we needed to update and then make our changes. Am I wrong?

 

          Invoice__c invoiceToUpdate = new Invoice__c();
                    invoiceToUpdate.Id = invoice.Id.ToString();
                    invoiceToUpdate.Open_Amount__c = Convert.ToDouble(tempTable.Rows[0]["InvoiceOpenAmt"]);
                    invoiceToUpdate.Open_Amount__cSpecified = true;

                    //Update this invoice in Salesforce
                    SaveResult[] results2 = binding.create(new sObject[] {
                              invoiceToUpdate });

                    if (results2[0].success) 
                    {
                        Console.WriteLine("An Invoice record with Id: {0} was updated.",
                                 results2[0].id);

                    } 
                    else 
                    {
                        Console.WriteLine("FAILURE to update Invoice record with Id: {0}",
                                   results2[0].id);
                    }

 

Thanks,
Calvin 

 



Best Answer chosen by Admin (Salesforce Developers) 
calvin_nrcalvin_nr

It was late night and I was using create() instead of update()..:)