EDIT. A lot of responses aren't really addressing my main confusion. Why is it so stuck? It was queued for 1:45 and it still is hanging there...

I used the structure of how I'm scheduling this based off of another project accomplishing a similar thing, but I think I might not understand it fully enough and it doesn't work. I want, every morning, a query to get all Orders with payment-due (field) > 0 and payment due date == today. Basically, getting orders with outstanding payments. I then want to use those orders and add 15% interest to an interest field.

So...it starts with this as the schedulable class...

global class interestScheduler implements Schedulable{
    global void execute(SchedulableContext SC) {
        Database.executeBatch(new ScheduledInterestCheck());


and here is scheduledInterestCheck...

global class ScheduledInterestCheck implements Database.Batchable<sObject>{    
    global Database.QueryLocator start(Database.BatchableContext BC){
        date today = date.today();
        date lastMonth = today.addMonths(-1);
        String query = 'SELECT interest_payment_overdue__c, total_payments__c, payment_due__c FROM Order2__c WHERE payment_due__c > 0 AND payment_due_date__c =: date.today()';
        return  Database.getQueryLocator(query);

    global void execute(Database.BatchableContext BC, List<Order2__c> latePayments){

    global void finish(Database.BatchableContext BC){

and lastly..

public class setInterest {
    public static void setAmount(List<Order2__c> orders){
        for(Order2__c o : orders){
            System.debug('Set Interest class ran');
            o.interest_payment_overdue__c = o.payment_due__c * 0.015;
            System.debug('' + o.Interest_Payment_Overdue__c);
        update orders;

And it seems intuitive enough, but I have a lot of failed executions after coming back from a couple weeks vacation, and when I deleted it and set it to schedule on an hour today, it just hung up in queued. Thoughts on what to do from here?

Scheduled Jobs

  • I don't see any error in your code. Could it be possible that your payment_due__c is null on some orders? Jan 13, 2017 at 17:16
  • So you think this should execute correctly starting with that schedulable class? I'm worried less about errors like that, since none are coming up and nothing at all seems to be happening. Furthermore, I don't believe a null payment_due__c would break anything, since I'm only using any that are > 0. Again, I'm not getting any errors, it seems nothing is happening at all Jan 13, 2017 at 17:19
  • 1
    Don't use the global access modifier...
    – Adrian Larson
    Jan 13, 2017 at 17:22
  • Might I ask why, for some insight on how this fixes the problem? Also, I can't save changes because it says there are jobs pending or in progress. Jan 13, 2017 at 17:27
  • It won't fix anything, you should just stop doing it. Stick with public unless you have a good reason not to. If you don't know what a good reason would be, then you haven't run into one yet. :)
    – Adrian Larson
    Jan 13, 2017 at 17:36

1 Answer 1


Scheduling is based on service availability. There's no guarantee it'll start exactly the second you specify. Very rarely, a job will get "stuck," though, and usually have you to delete it and reschedule it. If that doesn't fix the issue, contact support, because it's usually something wrong on the backend; you can't fix it, and neither can we (us, non-internal-salesforce-developer types).

In regards to your actual batch class, you can't call apex methods using dynamic queries, so :date.today() isn't valid. Also, you shouldn't generally use dynamic queries unless you absolutely need to, and you absolutely do not need to. Just use a normal, inline query. Also, you can use TODAY in your query instead of calling a method. The final version should look more like this:

global Database.QueryLocator start(Database.BatchableContext BC){
    return  Database.getQueryLocator([
        SELECT interest_payment_overdue__c, total_payments__c, payment_due__c 
        FROM   Order2__c 
        WHERE  payment_due__c > 0 AND payment_due_date__c = TODAY

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.