0

I have to get IDs of Call custom object from Incident Transaction custom object and run a for loop on call feeding the list. Can someone help me here?

   List<SObject> myCalls = [SELECT Call_abv__c FROM Incident_Transaction_abv__c];

   List<Call2_vod__c> Call= new List<Call2_vod__c>();

    for(Call2_vod__c cl:myCalls)
    {   

    }

Getting below error:

Compile Error: Loop variable must be of type SObject at line

7
  • why don't you use List of type Incident_Transaction_abv__c for the query result?
    – highfive
    Commented Dec 9, 2014 at 10:43
  • 1
    Your loop variable cl is of type Call2_vod__c while the structure myCalls is of type SObject. Your question is a bit unclear, though.
    – Mahmood
    Commented Dec 9, 2014 at 10:43
  • I have to fetch Call IDs from Incident transaction then do some update operation on the calls. @Mahmood Commented Dec 9, 2014 at 10:45
  • @highfive The result would be same. Commented Dec 9, 2014 at 10:45
  • 1
    You're looping Incident_Transaction_abv__c records with Call2_vod__c object! What are you trying to do?
    – Vignex
    Commented Dec 9, 2014 at 10:47

2 Answers 2

0

You need to typecast List of SObjects to List of relevant object. So your code should look like -

   List<SObject> myCalls = [SELECT Call_abv__c FROM Incident_Transaction_abv__c];
   List <Incident_Transaction_abv__c> myCallsInc = (List <Incident_Transaction_abv__c>) myCalls;
   List<Call2_vod__c> Call= new List<Call2_vod__c>();
   for(Incident_Transaction_abv__c ita : myCallsInc )
    {   

    }
1
  • Thanks Amit! I was failing here. But update needs to be done on Calls. I need for loop for calls. Commented Dec 9, 2014 at 10:53
1

myCalls is of type List<Incident_Transaction_abv__c>. You can't iterate over a more specific type than a less specific type without casting. You need to make the loop variable type and the list type agree with each other.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .