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
imhereimhere 

Class Cast Exception Custom object

i created a Custom Object : Area
using partner API .. create and describle call works fine.
But when i Query this object and cast it back in Area it gives Class Cast Exception

Folloing is the code:
queryResult = binding.query("select Name, City__c from Area__c");
while (queryResult.getRecords() != null)
{
for (int i = 0; i < queryResult.getRecords().length; i++)
{
LINE NO 425 Area con = (Area) queryResult.getRecords(i); // EXCEPTION ARISES HERE
String firstName = con.getName ();
String lastName = con.getCity__c();
System.out.println("Contact " + (i + 1) + ": " + firstName + " "
+ lastName);
}

queryResult = binding.queryMore(queryResult.getQueryLocator());
}

EXCEPTION IS :

java.lang.ClassCastException: com.sforce.soap.partner.sobject.SObject
at com.smartmicros.sforce.test.SamplesPartner.querySample(SamplesPartner.java:425)
at com.smartmicros.sforce.test.SamplesPartner.run(SamplesPartner.java:537)
at com.smartmicros.sforce.test.SamplesPartner.main(SamplesPartner.java:65)

I extended Area Object from SObject of parnters API.
wt i think is : SObject's instance is created and as the Instance is of base class it can not be Cast Down in Derived class's instance
would any one please guide me ?? The same Call for Account works fine using Enterprice API.
SuperfellSuperfell
You're using the partner API, there is only the sObject, none of the specific subclasses.
imhereimhere
then If i have to Query a custom Object ?
is there any way ???
i am trying to write my Own Ser and DeSer and registering my classes to the Bindings
as it is done in SoupBindingStub class of enterprise and partner API.
would it work ??
SuperfellSuperfell
Yes, you can access custom objects.

No, you can't register custom serializers/deserializers and have it work because at the XML level there is only the sObject type, no others, so you can't have the deserializer fire for MyCustomObject__c but not for Account. (for the parnter API).

for the enterprise API, re-download the WSDL after the custom object was created, then it'll be in the WSDL and WSDL2Java will create all the relevant classes needed.
imhereimhere
thx SimonF
i downloaded the enterprose WSDL. it worked fine.

If i include This code in Prtner's WSDL and run WSDL2Java on it.... would it work ??



.....
......



If doing wt described above is Useless ...
would u plz tell me wts the difference between Partner and Enterprise any LINK or Document wil be helpFull.

when i started using i thgt Custom Objects will be dealt Via Partner's API.
SOAP Request Envelop is same... SOAP response Envelop is same . I could not get where it differes?
SuperfellSuperfell
The differences are described in the docs, see the section on the partner API in the api docs. The on the wire messages are very similar, the main different is how they're described in the WSDL, the partner API is described in a generic way that allows you to write application that run on multiple different salesforce accounts, and can discover all the objects & fields dynamicly at runtime. The enterprise API WSDL is a much more strongly typed WSDL, it includes definitions of all the objects and fields it knows about including all the custom ones, at the downside of it not being able to handle new fields that get added after the wsdl was generated.