Print this page

Duplicate ID is returned using Partner WSDL

Knowledge Article Number 000171402
Description Currently the Partner WSDL returns the ID in index 0 when a query is requested and ID is included. Therefore, when we query for some sObject information the <sf:Id> tag is repeated, i.e. the ID field is returned twice.
Resolution SELECT Id From <SObject> returning the Id field twice when the Partner WSDL is used is "working as designed"
The first Id is for the Id element defined in the SObject type, the 2nd one appears to preserve the mapping from your query to the xsd:any section, i.e. you don't need to do anything special if you query Id, it'll appear in the xsd:any section just like any other field.
In other words, in order to support the Id property of an sObject, an implicit 'SELECT Id' is made on one's behalf.  If an additional, explicit, 'SELECT Id' is added to the query, the result is two identical <sf:Id> tags.
What's more, if you review the Partner WSDL, you'll notice the schema provides the below definition for queryResult: 
<complexType name="QueryResult"> 
<element name="done" type="xsd:boolean"/> 
<element name="queryLocator" type="tns:QueryLocator" nillable="true"/> 
<element name="records" type="ens:sObject" nillable="true" minOccurs="0" maxOccurs="unbounded"/> 
<element name="size" type="xsd:int"/> 
where the definition of sObject is as follows: 
<complexType name="sObject"> 
<element name="type" type="xsd:string"/> 
<element name="fieldsToNull" type="xsd:string" nillable="true" minOccurs="0" maxOccurs="unbounded"/> 
<element name="Id" type="tns:ID" nillable="true"/> 
<any namespace="##targetNamespace" minOccurs="0" maxOccurs="unbounded" processContents="lax"/> 
so "Id" is always provided at least once, and when you query for Id as well, the <any> tag will make "Id" show twice.

You may want to consider voting for the below idea that in case of being implemented in the future might make unnecessary to include ID in SOQL queries:

promote demote