Find your content:

Search form

You are here

Problem creating Iterable Batch Class

 
Share

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.


Attribution to: sfelf

Possible Suggestion/Solution #1

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.


Attribution to: sfelf

Possible Suggestion/Solution #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
}

}


Attribution to: Phil Hawthorn
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/4864

My Block Status

My Block Content