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
BOFHBOFH 

Update multiple fiels in Account

Hi all--

I'm attempting to update the Account Number, and two custom fields under Accounts using the partner WSDL, C#.net, and the SOAP API.  Anytime I do multiple fields nothing happens, but the program returns success.  If I only do one field at a time, it updates that field without a problem and also returns success.  Does anyone have any insight as to why this is happening?  Does SalesForce only let you update one field at a time?

Thanks.
james_galindojames_galindo
I'd need to look at your code, but SF does not restrict you to updating ONE field.  If it's a custom field are you sure it is structured with "__c" at the end?  Is it a boolena datatype? if so you need to set the "specified" attribute too.
BOFHBOFH
                for (int i = 0; i < length; i++)
                {
                    updateRec.Id = oraWork.returnValues("id", 0);  //gets the id of the record to update
                    updateRec.Any = new System.Xml.XmlElement[] { this.GetNewXmlElement("AccountNumber", oraWork.returnValues("orgid", 0)) };  //value is in a different class, oraWork.returnValues returns a string
                    UpdateRec.Any = new System.Xml.XmlElement[] { this.GetNewXmlElement("Primary_On_line_Account_Password__C", oraWork.returnValues("onlineaccountpassword", 0)) };//value is in a different class, oraWork.returnValues returns a string
                    updateRec.Any = new System.Xml.XmlElement[] { this.GetNewXmlElement("Primary_On_line_Account_Name__c", oraWork.returnValues("onlineaccountname", 0)) };//value is in a different class, oraWork.returnValues returns a string
                    updateRec.type = "Account";

                    SaveResult[] sr = binding.update(new sObject[] { updateRec });
                    for (int j = 0; j < sr.Length; j++)
                    {
                        if (sr[j].success)
                        {
                            Console.WriteLine("Success");
                            updateSuccess++;
                        }
                        else
                        {
                            Console.WriteLine("Fail");
                            updateFail++;
                        }
                    }
                }

I am able to do the ID field and any of the other fields if I do them one at a time.  I am sure the names are correct.  When I try to run this code as is, nothing happens and it returns success.  All three of the fields that I am updating are Text fields, and the value going into them, does not exceed the size that was placed on the field in SalesForce.  If you need anything else, let me know.

Thanks.
james_galindojames_galindo

I am not sure how you're currently appending elements to your static? doc, but you may need to use ImportNode instead of AppendChild.

I suspect you may be creating a new instance of an XmlDocument each time you call getNewXmlElement.

 

 

 

BOFHBOFH
I think you are right.  I poked around online a little bit this morning, and think I found something that will help.  Thanks for all of your help.
SuperfellSuperfell
You're overwriting the any collection with an array containing a single field (the 3 lines near the top that do updateRec.Any = ), you need to construct a single array with all the fields you want to update. your code if ecttively doing

string a = "1"
a = "2"
a = "3"
Console.WriteLine(a)

and your wondering why it only prints 3.