Dyna batch

Sometimes, after you write your code, you realize that you need to execute it slightly differently now and then. You could make a second version of your class, but what if there were three or four different situations? Remember, we don't like to write the same code twice; that's inefficient. If the only difference between your use cases are the records that need to be queried but the actual logic is the same, then you can easily add some flair to your implementation of the Database.Batchable interface and make it more dynamic!

//Apex Class that implements the Batchable interface global class dynaBatch implements Database.Batchable<SObject> { String queryString; global dynaBatch (String otherQueryString){ queryString = 'Select Id from ...

Get Learning Apex Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.