Batch Apex Flashcards
Why should Batch Apex be used?
To run large jobs that would exceed normal processing limits
Batch Apex is the best solution for what situation? Give an example
Processing a lot of records at once.
Data cleansing or archiving.
What are two advantages of Batch Apex?
1 - Each transaction starts with a new set of governor limits.
2 - If one batch fails, all other successful batch transactions aren’t rolled back
What interface must be implemented in a batch class?
Database.batchable
What three methods must be implemented in a batch class?
start
execute
finish
What happens in the finish method of a batch class?
Post processing operations once all batches are executed.
How many times is the finish method of a batch class called?
once
What happens in the execute method of a batch class?
the actual processing for each batch of data.
T/F - Batches of records are guaranteed to execute in the order they’re received from the start method
false
What two classes that can be returned from the start method?
Iterable
QueryLocator
How many records can be queried by a QueryLocator?
50 million
T/F - the governor limits on the number of records returned is enforced with a queryLocator.
false
What is a use case for a custom iterable class?
Looking through API results or pre-processing records prior to being passed into the execute method.
How many times is the start method of a batch class called?
once
How many times is the execute method of a batch class called?
Once for each set of 200 records processed by the batch.
How many records can be processed by a batch at a time?
200
What is the start method responsible for?
Collecting the records or objects to be passed into the execute method for processing.
How is a batch class invoked?
Database.executeBatch
How can the number of records processed in a batch be controlled?
the scope parameter of executeBatch
What is a use case for the scope parameter?
Running into governor limits when executing the default batch size.
What is created as a result of invoking a batch?
An AsyncApexJob record
T/F- by default batches are stateful
false
How many transactions are processed in a batch execution of 1000 records?
5
How is a batch made stateful?
implementing the Database.Stateful interface
Why is maintaining state in a batch class useful?
when counting or summarizing data across batch executions is necessary. Maintaining state does not clear class level variables across executions.
T/F - it’s a good idea to use Batch Apex when there are 200 records or less.
false