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
aebenaeben 

Winter 10 Batch Apex Issue

In sandbox that got upgraded to winter 10.

 

I am trying to return a Database.QueryLocation from the start method.

 

The release notes and the documentation for winter 10 clearly says that I can return either iterable or QueryLocator. But, in my code if  I say something like 

 

global Database.QueryLocator start(Database.BatchableContext ctx)

{

return Database.getQueryLocator('Some query here'); 

 

It does not compile.

  

Best Answer chosen by Admin (Salesforce Developers) 
aebenaeben

This is the syntax if you want to use the query locator.

 

class MyBatchApex implements Database.Batchable<SObject> //Has to be SObject and not a concrete type 

{

    Database.QueryLocator start(Database.BatchableContext ctx)

    {

        return Datebase.getQueryLocator('Your query here!!');

     }

 

     void execute(Database.BatchableContext ctx, List<SObject> sobjects) //Has to be SObjects

     {

    //Do the down casting here to a concreate type 

      } 

 

     void finish(Database.BatchableContext ctx)

     {

     }

}

 

This compiles and works. 

 

 

All Answers

jpwagnerjpwagner

Things to double check:

1.  api version 17.0

2.  verify with support that batch apex is enabled for this environment

 

Not enough info to help beyond that... 

aebenaeben

I am not executing it. Its at compile time.

 

If i change the return type to Iterable it compiles.

 

I don't want to use Iterbale because of the governence limits. 

aebenaeben

This is the syntax if you want to use the query locator.

 

class MyBatchApex implements Database.Batchable<SObject> //Has to be SObject and not a concrete type 

{

    Database.QueryLocator start(Database.BatchableContext ctx)

    {

        return Datebase.getQueryLocator('Your query here!!');

     }

 

     void execute(Database.BatchableContext ctx, List<SObject> sobjects) //Has to be SObjects

     {

    //Do the down casting here to a concreate type 

      } 

 

     void finish(Database.BatchableContext ctx)

     {

     }

}

 

This compiles and works. 

 

 

This was selected as the best answer