+ Start a Discussion

@Readonly - how is it at all useful in a scheduled job?

I'm trying to create an automated aggregate data summary tool by using a scheduled apex class in conjunction with a @Reaonly annotated method to get around the governor limit on number of rows queried. There are very specific limits to what can happen within a @Readonly method (no email, no DML, no @Future calls, etc) and there are also additional limitations put on Schedulable execute methods (can't return data, no callouts) so my question is, what good are scheduled @Readonly methods? There's no way to do anything with the data that's returned from the queries. Am I missing something?


I get the use of @Readonly in a visualforce context, but I don't see why special consideration wasn't made for schedulable readonly methods.


The only foreseeable use for ReadOnly with a Scheduled job would be to allow that scheduled job to kick of a batch job while passing in a large number of records. I don't believe that ReadOnly and Schedulable were meant to be used together. If you look at the language, you'll see other times that there are mutually exclusive modifiers as well. One wouldn't have an abstract interface or a final abstract class.


ReadOnly is a very useful attribute when used for its intended purpose. Why would you want to even think that a ReadOnly Scheduled job would be at all useful? Granted, perhaps in a future release they might allow callouts, or future methods, or some new type of "lite" DML. Just because something can be constructed doesn't mean it makes sense right now. There are several un-queryable/constructable SObject types, for example. The language used in those errors suggests that it might be in a future release.


Assuming you can't seem to find any useful means of using a ReadOnly Scheduled class doesn't mean it might not eventually have a use; it just might not make any sense right now. I'll ponder this myself over the next day or two and see if I can't come up with a reasonable use for it myself, because now I'm curious.