1

My scenario is: A future method is on a queueable class. Queueable job comes first before the Future job in the Apex Jobs. Upon checking the completion date(time), the future method is completing first before the queueable.

The queueable is getting the ids that needs to be processed and creating/updating a custom object record while the future is using the ID for updating the custom object record by HTTPResponse.

enter image description here

The queueable that has 12:48AM completion date(time) is updating the custom object record that the future method has already update (12:47). My question is, is there a chance to delay the running of future method since they are both async? Thank you.

1
  • 1
    If the Queueable calls the future method, it will complete first before the future method starts. You may be misinterpreting the logs. Without seeing your code, there's not much more we can say about this, though.
    – sfdcfox
    Aug 2, 2019 at 13:48

3 Answers 3

2

There is no surity that one async apex will run before another async when they are invoked separately (or rather paralelly).

Instead what you can do is, invoke the future from queueable execute method like below:

public class poc {

    public class myqueue1 implements Queueable {
        public void execute(QueueableContext context) {
            // some logic  
            myFuture();
        }
    }

    @future
    public static void myFuture(){
        // logic
    }
}

OR, convert the future into queueable and invoke it at the end of 1st queueable execute method. Example:

public class poc {

    public class myqueue1 implements Queueable {
        public void execute(QueueableContext context) {
            // some logic  
            System.enqueueJob(new myqueue2());

        }
    }

    public class myqueue2 implements Queueable {
        public void execute(QueueableContext context) {
            //some logic      
        }
    }
}
1
  • Converting your @future method into a queueable Class and setting up the chain seems like the way to go here. Aug 2, 2019 at 19:49
1

@future methods & Queueable are enqueued in a message queue that doesn't guarantee execution order. Convert the future method into Queueable class and enqueue.

0

Asynchronous method do not guarantee running time, it just like whichever get the resource first will get executed first despite of the fact which is called first.

So, instead of doing dependent things in future and queueable methods, you should go with the queueable chaining. first get the record IDs which currently and enqueue another job which will utuilize those IDs to do rest of the processing.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .