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
LosintikfosLosintikfos 

ClassCastException

Hi Experts,

Do anyone knows why i am getting ClassCastException from below code?

Code:
sObjects[] = queryResult.getRecordsArray();
 for (int j = 0; j < sObjects.length; j++) {
     Account obj = (Account) sObjects[j];
           String id = obj.getId();
    }

com.sforce.soap.enterprise.sobject.impl.SObjectImpl cannot be cast to com.sforce.soap.enterprise.sobject.Account



Message Edited by Losintikfos on 10-01-2008 05:59 AM
Best Answer chosen by Admin (Salesforce Developers) 
LosintikfosLosintikfos
Sorted!

All Answers

SuperfellSuperfell
your queryResult does not contain accounts ?
LosintikfosLosintikfos
It does SimonF!

Doing something like this;

Code:
Query query = Query.Factory.newInstance();
   query
     .setQueryString("select Id, Name from Account where Account_Status__c != 'inactive'");
   QueryDocument queryDocument = QueryDocument.Factory.newInstance();
   queryDocument.setQuery(query);


   QueryResponseDocument queryResponseDocument = dbcon.stub.query(
     queryDocument, dbcon.sessionHeaderDocument, null, null);

   QueryResponse queryResponse = queryResponseDocument
     .getQueryResponse();

   QueryResult queryResult = queryResponse.getResult();

 



LosintikfosLosintikfos
I have another app which uses the same cast and works perfect!
It's the once i have deployed to the web service server which pops up with the exception.
LosintikfosLosintikfos
Hi Experts,

Do anyone know why i can't cast Account to SObject in webservice?

Doing something like this: Account obj = (Account) sObjects[j] and keeps getting ClassCastException - seem everyline of the code if fine apart from this cast.

Experts advice pls.


Message Edited by Losintikfos on 10-02-2008 01:11 AM
LosintikfosLosintikfos
Sorted!
This was selected as the best answer