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
DarwinDarwin 

Invalid element in com.sforce.soap.enterprise.sobject.SObject - Plan_Summe__c

Hello,
 
handling the sforce - API is quiet new to me. I think it's the best way to describe what I've already done:
 
I've downloaded the Enterprise WSDL, and succeeded in generating customer object classes.
 
When I try to query any one of these customer object, I get the message above.
...
queryString = "select Plan_Summe__c from Projekt__c";
        try {
            qr = binding.query(queryString);
            boolean done = false;
            if (qr.getSize() > 0) {
                while (!done) {
                    for (int i = 0; i < qr.getRecords().length; i++) {
                        Projekt__c records = (Projekt__c) qr.getRecords(i);
                        System.out.println("Summe: " + i + " " + records.getPlan_Summe__c());
                    }
...
 
When I try to bypass the 'invalid field' problem by using an ID-field as it is used in alle SObject classes, I will encounter a ClassCastException. Querying a standard SObject (e.g. Contact) works fine. The debugger showed that the QueryResult contains an array of com.sforce.soap.enterprise.sobject.SObject when it should instanciate com.sforce.soap.enterprise.sobject.Projekt__c.
 
What could be the problem?
 
Thanks in advance.
Andy
 
 
SuperfellSuperfell
Download the enterprise WSDL again, it sounds like you added the custom object + fields after the first download of the WSDL.
DarwinDarwin
Hello Simon,
 
I suppose not. I've followed your advice, downloaded the wsdl file again and generated the java classes once more. The error is still there.
 
I've tried to take out some complexity for testing: My query string is now "select Id from Projekt__c".
I've used the method .getId(int). Since Id is a standard field the error doesn't occur anymore. (Of course that was not the goal. I don't want the Id but my field.)
 
Anyway: Below there is the content of the QueryResult. Why does the qr contain SObject[] instead of Projekt__c[] ?? It seems to query the right table, but is unable to create an instance of the right class? That doesn't make sense to me.
 
qr= QueryResult  (id=134)
 __equalsCalc= null
 __hashCodeCalc= false
 done= true
 queryLocator= null
 records= SObject[88]  (id=177)
  <= shouldn't this be records = Projekt__c[88] (id=177)
  [0]= SObject  (id=180)                <=                                 [0] = Projekt__c (id=180)
.... 
 size= 88

SuperfellSuperfell
The array will always be an array of Sobject, but each item in the array can be a subclass of SObject (e.g. account). If the individual items in the array are also SObject, then make sure you're sending the request to the enterprise endpoint URL. Which version of Axis are you using ?
DarwinDarwin
Hello Simon,
 
I'm using the axis.jar that came with quickstart7.0. I guess that's Axis 1.1.
 
Concerning the endpoint: uri = new SforceServiceLocator().getServiceName().getNamespaceURI();
The value after login:
uri = "urn:enterprise.soap.sforce.com"
loginResult.getServerUrl() = "https://eu0-api.salesforce.com/services/Soap/c/7.0"
I understand that the array contains objects of SObject. But shouldn't it be objects of my customer object class (extends SObject)?
 
Would it help you if I would send you a couple of lines from the SOAP reponse?
 
Cheers
Andy
SuperfellSuperfell
Yes, the objects in the array should be the subclass, which makes me think the code you're running is not the new code you generated from the WSDL.
DarwinDarwin
Hello Simon,
 
it was your last sentence that solved the riddle. I assumed that I only have to import the new customer java classes.
WSDL2Java also generates a new SoapBindingStub class. The method addBindings0() fills a cache array of all SObject subclasses that can be created by the stub.
As long as the old version of this class is running, customer objects can not be created.
 
Thank you.
java devjava dev

Hi Andy Iam also getting the same problem you got?, I have genetrated new stubs using new WSDL . I have added a Quotes App & now I want to query that custom object.

My Query is

"binding.query("select opportunity__c from SFDC_520_Quote__c")" and iam getting same error as You.

 Iam able to get Metadata of that custom Object.

Can u please tell me how could you solved it. 

Sudheer Tumu