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
dave6dave6 

Getting ClassCastException using Enterprise WSDL (Java)

I'm using the Enterprise WSDL and I'm getting the following error performing a query to get a Transaction__c record by record ID.  I've used this WSDL in many other Java applications with no problems, I'm not clear what could be causing this.  This is a fairly new record type we have in our WSDL but I have used it in other apps with no issues.

Some app details.  I'm using force-wsc version 31.1.0 and the same version to generate the source code from the WSDL.  The exception stack trace is below.  I'm not clear how this could happen because Transaction__c does implement XMLizable

java.lang.ClassCastException: com.sforce.soap.enterprise.sobject.Transaction__c cannot be cast to com.sforce.ws.bind.XMLizable
at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:650)
at com.sforce.ws.bind.TypeMapper.readArray(TypeMapper.java:551)
at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:529)
at com.sforce.soap.enterprise.QueryResult.loadFields(QueryResult.java:137)
at com.sforce.soap.enterprise.QueryResult.load(QueryResult.java:121)
at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:651)
at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:527)
at com.sforce.soap.enterprise.QueryResponse_element.loadFields(QueryResponse_element.java:62)
at com.sforce.soap.enterprise.QueryResponse_element.load(QueryResponse_element.java:54)
at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:651)
at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:527)
at com.sforce.ws.transport.SoapConnection.bind(SoapConnection.java:174)
at com.sforce.ws.transport.SoapConnection.receive(SoapConnection.java:148)
at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:99)
at com.sforce.soap.enterprise.EnterpriseConnection.query(EnterpriseConnection.java:674)

-Dave
logontokartiklogontokartik
You might have a namespace conflict which is causing the issue. Have you use WSDL2apex t generate your classes? can you try creating with new namespace?
dave6dave6
Yeah I originally thought maybe it was a namespace conflict but it seems right. I've checked and Transaction__c (in the namespace shown in the stack trace) does implement com.sforce.ws.bind.XMLizable so it all seems correct but maybe I'm missing something? I generate the source code using force-wsc as documented here: https://github.com/forcedotcom/wsc (generating stubs from WSDL). I'm not familiar with WSDL2apex, is that a different way to do the same thing? Note I'm using the Enterprise WSDL and need to generate the client classes that wrap that and make the connection/etc. -Dave
logontokartiklogontokartik
Sorry I mean WSDL2Java, can use use Apache WSC to build your client classes. Here is a blog with some info about the exception, hope this helps you out.

http://www.tgerm.com/2010/08/wsc-apache-axis-classcastexception.html 
dave6dave6
Yes that did help, thanks a lot. Although I'm not using AXIS in my app I think the problem was that since I do implement a Salesforce notification WSDL...it generates a SObject class that although does not implement XMLizable it is in the same package as the SObject generated by the Salesforce enterprise WSDL...so that class must having been loaded by the classloader and was preventing Transaction__c to be created. It seems that Salesforce should use different namespaces for each of their services/WSDLs so this can't happen? Thanks! -Dave