Every documentation on batch apex class shows the queryString variable declared as global. Is there a specific reason for doing so??

1 Answer 1


It does not need to be global or indeed there at all.

You can use compile-time checked static SOQL in the start method instead which is often a cleaner approach e.g.:

public Database.QueryLocator start(Database.BatchableContext bc) {
    return Database.getQueryLocator([select Name from Account]);

and the class and methods can be public instead of global.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.