In Salesforce, batch classes must be accessible by the platform’s batch processing framework to execute properly. The
Database.Batchable interface is designed for processing large volumes of data asynchronously.
When you implement Database.Batchable, the Salesforce platform needs to instantiate and call your class methods (start,
execute, and finish) during batch execution. If your class is declared as public instead of
global, the platform cannot access it from outside your namespace.
This restriction exists because:
- The batch processing framework runs in the system context
- It needs cross-namespace access to your batch class
- Only
global classes can be accessed across different namespaces in Salesforce
Without the global modifier, your batch job will fail to execute, even though the code compiles successfully. This can lead to silent
failures where scheduled batches simply don’t run.
What is the potential impact?
The batch job will fail to execute, preventing the processing of large datasets. This can cause:
- Data processing delays or complete failures
- Scheduled operations that silently don’t run
- Business processes that depend on batch processing to malfunction
- Difficulty in debugging since the error may not be immediately apparent