[SalesForce] Type casting error

I am getting runtime type casting error with below code. Can someone please help?

Code:

global class batchCallUpdate implements Database.Batchable<sObject> {
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'SELECT Call_abv__c FROM Incident_Transaction_abv__c';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<Call2_vod__c> scope) {
         for(Call2_vod__c a : scope)
         {
             a.Incidents_Count__c = [SELECT count() FROM Incident_Transaction_Line_Item_abv__c WHERE (Call_Sample_abv__r.Call2_vod__c=:a.id
or Call_Sample_abv__r.Call2_vod__r.Parent_Call_vod__c=:a.id) or (Call_detail_abv__r.Call2_vod__c=:a.id
or Call_detail_abv__r.Call2_vod__r.Parent_Call_vod__c=:a.id)];            
         }
         update scope;
    }   

    global void finish(Database.BatchableContext BC) {
    }
}

Error: System.TypeException: Invalid conversion from runtime type
LIST to LIST

Class.IncidentListActionController1

Best Answer

Mahmood has it exactly, the reason for the runtime casting error is as follows

Your start method

global Database.QueryLocator start(Database.BatchableContext BC) {
    String query = 'SELECT Call_abv__c FROM Incident_Transaction_abv__c';
    return Database.getQueryLocator(query);
}

returns a list of Incident_transaction_abv__c SObjects

but the execute method ...

global void execute(Database.BatchableContext BC, List<Call2_vod__c> scope) { ...

is expecting a list of a different SObject Call2_vod__c. As custom Sobjects don't support subclassing, SFDC, while invoking the execute() fails casting the list of Incident_transaction_abv__c to a list of Call2_vod__c

You need to rethink your batch class design objectives in light of your schema

Related Topic