Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I am trying to create an Iterable Batch Apex Class that Allows Callouts and is Stateful. When I try to save the class I keep getting an error message that says:

Save error: Type arguments do not match type parameters for : Iterable<t>

Below is the code I am trying to save:

global class SampleIterableBatch implements Database.batchable<Map<String, String>>,
                                            Database.AllowsCallouts, Database.Stateful {

    global final List<Map<String, String>> updates;

    global SampleIterableBatch(List<Map<String, String>> updates) {
        this.updates = updates;
    }

    global Iterable<Map<String, String>> start(Database.BatchableContext info) {
        return updates;
    }

    global void execute(Database.BatchableContext info, List<Map<String, String>> scope) {
        // Do Something
    }

    global void finish(Database.BatchableContext info) {
        // Do Something
    }
}

Interestingly enough I don't get the error message if I remove the Database.AllowsCallouts and Database.Stateful. Any ideas why this error message is appearing and how to resolve it?

Note: I am seeing this error when I am saving edits to the class from the Force.com IDE.

share|improve this question
    
Does it say which line is causing the error? –  Mike Chale Nov 28 '12 at 20:07
    
@MikeChale yes, it says the line causing the error is line 0 –  sfelf Nov 28 '12 at 20:09
    
@MikeChale when I try to edit and save the class from within Salesforce the error message is: "Error: Compile Error: Type arguments do not match type parameters for : Iterable<t> at line -1 column -1". –  sfelf Nov 28 '12 at 20:13
    
Any update from SFDC on if the bug fix is planned? I've been experiencing something similar, and came across this post. –  aj2taylo Apr 2 '13 at 17:30
    
No I haven't heard anything back from SFDC on if or when a bug fix is planned. The workaround mentioned below has been working for me in the mean time. –  sfelf Apr 2 '13 at 19:56

2 Answers 2

I think there might be an issue with the editor, through pure chance I managed to get it to save by doing the following:

Original error:

enter image description here

Changed the parameter types to one that I knew would work and successfully from a previous project and save:

enter image description here

Then, change the type parameters back to the original:

enter image description here

Bizarre proof that it did actually save:

enter image description here

EDIT: This only seems to happen on editing in the Web IDE, i.e. you can save successfully first time but not subsequent times. Confirmed that the following code does work with output in dev console:

global class BatchMatching4 implements 
Database.Batchable<Map<String,String>>, 
Database.AllowsCallouts, Database.Stateful 
{   
    global Iterable<Map<String,String>> start( Database.BatchableContext BC )
    {
        return new List<Map<String,String>>{ new Map<String,String>{ 'key'=>'value' }};
    }

    global void execute(Database.BatchableContext info, List<Map<String,String>> scope) {
        System.debug( JSON.serializePretty( scope ));
    }

    global void finish(Database.BatchableContext info) {
        // Do Something
    }
}

EDIT 2: Having now had to do something very similar to the original problem, I found that by far the least troublesome way to do this is to use Object as the Type and cast accordingly in your execute method:

global class SampleIterableBatch implements Database.batchable<Object>,
                                        Database.AllowsCallouts, Database.Stateful {

global final List<Map<String, String>> updates;

global SampleIterableBatch(List<Map<String, String>> updates) {
    this.updates = updates;
}

global Iterable<Object> start(Database.BatchableContext info) {
    return updates;
}

global void execute(Database.BatchableContext info, List<Object> scope) {
   for( Object item : scope ) {
      Map<String, String> myMap = (Map<String, String>)item;
   }
}

global void finish(Database.BatchableContext info) {
    // Do Something
}

}

share|improve this answer
1  
Sounds like you are suggesting that there isn't anything wrong with the code and the issue is with Salesforce validating the code. Is this correct? Sounds like the solution then is to write the whole class without saving and hope that it doesn't need to be edited. –  sfelf Nov 28 '12 at 23:28
    
Yes, I am - as I mention above, the code does actually run/work. If I were you, I would write the main implementation logic in another 'helper' class and then you'll have minimal/boiler plate code in the Batch Apex class anyway. If you edit the main Batch Apex class in the Web UI you should be able to circumvent the problem by giving the class name a new name each time. Bizarre! –  Phil Hawthorn Nov 29 '12 at 7:25
    
Thank you so much for the clarification as well as the suggestion. I will open a case with Salesforce on this issue as well. –  sfelf Nov 29 '12 at 14:35
1  
@sfelf, no problem - would be interested to see where you get to with it from SF - would you mind creating an answer when you get one? Thanks –  Phil Hawthorn Nov 29 '12 at 14:37
1  
Also note that unless your want the 'global' access modifier, you no longer need it these days to implement Batch Apex interfaces. Useful if your producing a managed package with this code in. –  Andrew Fawcett Dec 7 '12 at 9:25
up vote 3 down vote accepted

I opened a case with Salesforce Support on this issue received the response below. It looks like this is a bug so for now one of the workarounds discussed in the other answers is going to be the best method to get around this issue.

I was following up your case # 08450637.

I would like to inform you that I have got an update from Tier 3 wherein they have informed that this issue is a known issue which is already under our observation and our R&D team is working on it.

Unfortunately, I will not be able to provide you a date when this issue will cease to exist. For now, we will change the status of the case to "Bug Fix submitted" and you will be notified once the issue is resolved.

We do apologize for the inconvenience caused due to this.

share|improve this answer
    
good to know, at least we weren't going mad :) –  Phil Hawthorn Jan 2 '13 at 18:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.