Today while working on one of requirement, where we need to schedule a job after every fixed interval of time. During unit testing we found our job stuck. Initially we thought, it may be because of non-availability of resources, since scheduled jobs get queued if resources are not available and runs as soon as resource is free. After waiting for 30 mins, we went to Setup >> Jobs >> Apex Jobs to see what is status of Batch Apex. We found that 'Scheduled Apex' i.e. scheduler was in 'Queued', while the 'Batch Apex' i.e. batch was in 'Failed' status. It was causing job to stay stuck.
First error: Future method cannot be called from a future or batch method
We need to be careful against such scenario. We may think that our job is running properly, whereas it may be in stuck status because of exception. We need to do follow to avoid such issue:-
1. Properly unit test job, with all possible use case and mass data. Don't test only for 1 batch, make sure to test it with multiple job.
2. Even after all test, make sure you check health of your job on production environment regulary. Otherwise if error, potentially it may already having impact on your desired business objective.
First error: Future method cannot be called from a future or batch method
We need to be careful against such scenario. We may think that our job is running properly, whereas it may be in stuck status because of exception. We need to do follow to avoid such issue:-
1. Properly unit test job, with all possible use case and mass data. Don't test only for 1 batch, make sure to test it with multiple job.
2. Even after all test, make sure you check health of your job on production environment regulary. Otherwise if error, potentially it may already having impact on your desired business objective.
Comments
Post a Comment