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
SFDC to Java ConnectorSFDC to Java Connector 

A duplicate value was specified for field 'LastName' in object 'Contact

Hi,

 

"A duplicate value was specified for field 'LastName' in object 'Contact', duplicate value 'Prabhu' prior value 'Muthu'"

this is an exception while am trying to upsert a value in salesforce using partner wsdl and jax-ws.

I am fetching RDBMS table values using jdbc and trying to insert the values into salesforce.

 

Here is my code snippet,

 

DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
            Document doc = docBuilder.newDocument();

Upsert upsert = new Upsert();

SObject sobj = new SObject();

 

 

ResultSet rs = stmt.executeQuery(query);

 

while(rs.next())
            {
                sobj.setType(objname);
                
                sobj.setId("objectfromjava");
                for (int i = 0; i < clc; i++) {          // clc - number of columns : column count

                    
                    Element insert = doc.createElement( columnValue[i]);
                    insert.appendChild(doc.createTextNode(rs.getString((i+1)).toString()));                
             

                   sobj.getAnies().add(insert);



                }
                upsert.getSObjects().add(sobj);
         
            }

 

 

port.Upsert(upsert);

 

 

The same error is happening for create call also..

 

what will be my problem? Please help me out!!

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

Oh, and the most likely problem is that you're not creating a new sobject for each row, so you just keep adding elements over and over to the same one sobject.

All Answers

SuperfellSuperfell

Can you post what your request XML looks like? the error would indicate that you have the lastName field twice, e.g. <lastName>foo</lastName><lastName>bar</lastName>

SuperfellSuperfell

Oh, and the most likely problem is that you're not creating a new sobject for each row, so you just keep adding elements over and over to the same one sobject.

This was selected as the best answer
Abhinav GuptaAbhinav Gupta

Thats correct Simon, this operation should be done inside iteration(while loop)

 

SObject sobj = new SObject();

SFDC to Java ConnectorSFDC to Java Connector

Thank you Mr. Simon, I will try out...

SFDC to Java ConnectorSFDC to Java Connector

Thank you Zindalabhinav!!