I am new to scheduled batch apex jobs. I am trying to run a job every day at 10 AM and 10 PM but the logic doesn't seem to be working. Here's what I have so far
Time currentTime = Datetime.now().time();
Time desiredStartTime = Time.newInstance(10, 0, 0, 0);
Integer minutesFromNow = 0;
minutesFromNow = ((desiredStartTime.hour() * 60) + desiredStartTime.minute()) - ((currentTime.hour() * 60) + currentTime.minute());
if (minutesFromNow <= 0) minutesFromNow = minutesFromNow + 720;
When it tries to run at 10PM it gives me this error - First error: minutesFromNow must be non-negative