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
aalazzaniaalazzani 

Error with Update statement in C# .NET

I am getting this error when I try to run the code below. Please help.

Error:

System.Web.Services.Protocols.SoapHeaderException was unhandled
  Message="A duplicate value was specified for field 'Id' in object 'Opportunity', duplicate value '00650000008ov0VAAQ' prior value '00650000008ov0VAAQ'"

_______________________________________________________________________________ 

Code:

 

sObject[] myOppties;

myOppties = sfdc.retrieve("Id, AccountId", "Opportunity", new String[] { "00650000008ov0VAAQ", "00650000008mpS4AAI", "00650000008m20QAAQ" });

for (int i = 0; i < myOppties.Length;i++)

{

if (myOppties[i].Any[0].InnerText == "00650000008m20QAAQ")

{

myOppties[i].Any[1].InnerText = "0015000000IRt4nAAD";

}

System.Console.WriteLine(myOppties[i].Any[0].InnerText + " " + myOppties[i].Any[1].InnerText);

}

SaveResult[] mySaveResult = sfdc.update(myOppties);

ZitizonXZitizonX

Hi aalazzani,

When you paste ur code next time put in a SRC (CODE) box which you can find on the Message body tool bar. Otherwise its pretty hard to find the reply button link to your posts :smileytongue:

The System.Web.Services.Protocols.SoapException is thrown when you have an invalid username or password! Check your username and password.

Ta

Zitizon X

ZitizonXZitizonX
Hit the tab button to go to right :smileywink: (in case if you didnt knw that)
aalazzaniaalazzani

Sorry, this is the first time I am using the discussion board. Here is the code:

Code:

sObject[] myOppties;

                myOppties = sfdc.retrieve("Id, AccountId", "Opportunity", new String[] { "00650000008ov0VAAQ", "00650000008mpS4AAI", "00650000008m20QAAQ" });

                for (int i = 0; i < myOppties.Length;i++)
                {
                    if (myOppties[i].Any[0].InnerText == "00650000008m20QAAQ")
                    {
                        myOppties[i].Any[1].InnerText = "0015000000IRt4nAAD";
                    }

                    //myOppties[i].Id = myOppties[i].Any[0].InnerText;

                    //myOppties[i].Any[0].InnerText = "";

                    System.Console.WriteLine(myOppties[i].Any[0].InnerText + " " + myOppties[i].Any[1].InnerText);
                }

                SaveResult[] mySaveResult = sfdc.update(myOppties);

                if (mySaveResult[0].success)
                {
                    System.Console.WriteLine("Update Success!");
                }
                else
                {
                    System.Console.WriteLine("Update Failed!");
                }


 

aalazzaniaalazzani
But if the un and pwd are not correct no session will be created and I will not be able to query any data which is not the case. I used the getupdated call and I retrieved records. Any other ideas.
 
Is the code that I wrote correct to update a record in SFDC? I am new to the Apex platform.
FreakazoidFreakazoid

I'm new to Apex myself and received this same error message just yesterday.  I found that you cannot include the Id field in the retrieve call.  You get the Id field value automatically in the .Id member of the sobject array returned from the retrieve call.  Use the .Id member and not .Any[0].InnerText.  The .Id member of the sobject object is used to determine which record to update.

Remove the Id field from your retrieve statement and evaluate .Id member like this.

Code:

if (myOppties[i].Id == "00650000008m20QAAQ")
{
     myOppties[i].Any[1].InnerText = "0015000000IRt4nAAD";
}


 

Good luck!