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
java devjava dev 

Not able to query custom objects - Invalid element in com.sforce.soap.enterprise.sobject.SObject

Hi there,
   I am not able to query custom objects like 'Quote' through java.
a) I am able to get the metadata for the 'SFDC_520_Quote__c' object, but am not able to retreive any fields other than id.
b) I get results in the SForce explorer SOQL window for the query 'select Id, opportunity__c from SFDC_520_Quote__c'.
c) I get the the exception for the following line:

qr = binding.query("select Id, opportunity__c from SFDC_520_Quote__c");

Sep 18, 2006 5:30:22 PM org.apache.axis.client.Call invoke

SEVERE: Exception:

org.xml.sax.SAXException: Invalid element in com.sforce.soap.enterprise.sobject.SObject - Opportunity__c

at org.apache.axis.encoding.ser.BeanDeserializer.onStartChild(

at org.apache.axis.encoding.DeserializationContext.startElement(

at org.apache.axis.message.SAX2EventRecorder.replay(


If Sforce explorer exposes the field, you may have a permissions issue. Verify that your account has read priviledges on the fields in question. You also might let Sforce explorer write the query for you to make sure you have the correct names.

i done what you said.

1. i have the right to modify this object
2. the select stetment is running in sforce explorer...

My error: org.xml.sax.SAXException: Invalid element in com.sforce.soap.enterprise.sobject.SObject - First_Name__c

On this code: 
binding = (SoapBindingStub) new SforceServiceLocator().getSoap();
loginResult = binding.login(User, Password);
 binding._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY, loginResult
   SessionHeader sh = new SessionHeader();
  String sforceURI = new SforceServiceLocator().getServiceName()
    binding.setHeader(sforceURI, "SessionHeader", sh);
QueryResult qr = binding.query("Select c.First_Name__c from Candidate__c c");

in Candidate__c.static i have:
            elemField = new org.apache.axis.description.ElementDesc();
            elemField.setXmlName(new javax.xml.namespace.QName("", "First_Name__c"));
            elemField.setXmlType(new javax.xml.namespace.QName("", "string"));
in WSDL i have:
<complexType name="Candidate__c">
                    <extension base="ens:sObject">
                        <element name="Email__c" nillable="true" minOccurs="0" type="xsd:string"/>
                        <element name="Events" nillable="true" minOccurs="0" type="tns:QueryResult"/>
                        <element name="First_Name__c" nillable="true" minOccurs="0" type="xsd:string"/>
                        <element name="Histories" nillable="true" minOccurs="0" type="tns:QueryResult"/>
                        <element name="IsDeleted" nillable="true" minOccurs="0" type="xsd:boolean"/>
                        <element name="Last_Name__c" nillable="true" minOccurs="0" type="xsd:string"/>
                        <element name="Name" nillable="true" minOccurs="0" type="xsd:string"/>
                        <element name="Notes" nillable="true" minOccurs="0" type="tns:QueryResult"/>

And i have

Your logged in server id is:
Your logged in URI id is:

in my wsdl i change Soap/c/11.1 in Soap/u/11.1 but the serverUrl stay the same
 <!-- Soap Service Endpoint -->
    <service name="SforceService">
        <documentation>Sforce SOAP API</documentation>
        <port binding="tns:SoapBinding" name="Soap">
            <soap:address location=""/>

On other question is: How  can i regenerate my stub?
And the second one: How can i genetrated new stubs using WSDL ?

Do you have another Idea?



Message Edited by magda on 12-12-2007 04:31 AM

Message Edited by magda on 12-12-2007 04:32 AM

Message Edited by magda on 12-12-2007 04:37 AM

Message Edited by magda on 12-12-2007 07:33 AM
You should be able to go through the same steps that you went through when you initially generated the stub.

Make sure that you aren't referencing some other jar file in your path that might have and old version of the generated file.  I've seen people take the generated classes from the quickStart for example and try to use those on there own orgs.



thank you for your answer. But I don't know how i can generate the stub.
I do what you said, with the quickstar and modify this one. Could you please explain me what i have to do to generate a stub?

Today morning i try to create a new Projekt, with Sopa
without namespaceprefix.
And I'm becoming an exception during the project creation

ConnectionException: Unexpected element. Parser was expecting element '' but found ''

Message Edited by magda on 12-12-2007 11:30 PM
Hey magda,

Login to your developer edition and download the wsdl that you want to use (Enterprise or Partner).  Save that wsdl and use the available java tools to create the stub. 

There are many different methods for creating the stub depending on your java development environment.  I recommend using Apache Axis 1.2.  There are easy instructions on the apache axis site that describe how to generate the code using a command line.
thx very much.

What I done (if other peolpe have the same problem)

1 install Tomcat
2 download axis
3 in tomcate/weapps copie webapps/axis
4 install xml parser xerces J bin
5 add xml-aps.jar  and ercesImpl.jar in AXISCLASSPATH
6 add tomcat in Eclipse (properties/server)
7 download WSDL from salesforce
8 on WSDL generate Client / Deploy Client

I think there are other possibilities. But I'm very happy because it is now running without Exception.
I can now begin to build my Application ;)

Mr. Kirill YunussovMr. Kirill Yunussov
This error indicates that your Salesforce client cannot recognize the SObject type, so it's not able to interpret any of that SObject's fields other than ID. 

To resolve - not only do you need to import the new object's definition into your WSDL, you also need to update the qName section of your com.sforce.soap.enterprise.SoapBindingStub class to reference this new SObject type.  Looks something like this:
qName = new javax.xml.namespace.QName("", "My_New_Object__c");
cls = com.sforce.soap.enterprise.sobject.My_New_Object__c.class;

If you don't update SoapBindingStub class - you will still be able to query the new SObject, but no fields except the ID field.  For any other fields, you will get the following error:

org.xml.sax.SAXException: Invalid element in com.sforce.soap.enterprise.sobject.SObject - Custom_Field__c