How many times can you spot the letter "e" in:
Q: Create Batch Apex I'm having trouble creating a BATC apex. I need to make a condition in the start method
If the record type of opportunity equals donation executes a query if the record type = membership runs another query
global Database.QueryLocator start(Database.BatchableContext BC){
   ;  

// if (r.DeveloperName.equals('Donation')){
 /*   return Database.getQueryLocator([
                SELECT Id, (...) Where Amount__c > 50
           else {
           */
            return Database.getQueryLocator([
                SELECT  Name, (....) Where Amount__c < 50

           ]); 

But that doesn't result. Can anyone help?

A: Use this method like this:
String batchQuery;  

if (r.DeveloperName.equals('Donation'))
{
    batchQuery = 'SELECT id FROM... Amount < 50';
}
else 
{
     batchQuery = 'SELECT id FROM... Amount > 50';
}

return Database.getQueryLocator(batchQuery);


A: I always generate my queries for batches outside the batch - makes it easier to set, especially for testing...
So you have a batch class like this:
global class myBatchClass implements Database.Batchable<sObject> {

public String query;

global database.querylocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query);
}

And then I invoke it like this:
myBatchClass thisBatch = new myBatchClass();

String batchQuery;

if (r.DeveloperName.equals('Donation') ) {
    batchQuery = 'SELECT id FROM... Amount < 50';
}
else  {
    batchQuery = 'SELECT id FROM... Amount > 50';
}

kwBatch.query = batchQuery;
database.executebatch(thisBatch);


user
The total number of "e"s in that passage is one hundred and thirty-eight.
assistant