Activity Forums Salesforce® Discussions Queueable methods are functionally equivalent to future methods, so where to use which one make it clear please?

  • PRANAV

    Member
    August 29, 2016 at 2:33 pm

    Hi Tanu,

    Queueable Apex allows you to submit jobs for asynchronous processing similar to future methods with the following additional benefits:

    • Non-primitive types: Your Queueable class can contain member variables of non-primitive data types, such as sObjects or custom Apex types. Those objects can be accessed when the job executes.
    • Monitoring: When you submit your job by invoking the System.enqueueJob method, the method returns the ID of the AsyncApexJob record. You can use this ID to identify your job and monitor its progress, either through the Salesforce user interface in the Apex Jobs page, or programmatically by querying your record from AsyncApexJob.
    • Chaining jobs: You can chain one job to another job by starting a second job from a running job. Chaining jobs is useful if you need to do some sequential processing.

    Queueable Versus Future

    • If you were exceeding a governor limit in your future method, or if you think a future method requires a higher limit, you can possibly increase the limits for your future method with the Future Methods with Higher Limits pilot.
    • Another reason to use future methods instead of queueable is when your functionality is sometimes executed synchronously, and sometimes asynchronously. It’s much easier to refactor a method in this manner than converting to a queueable class. This is handy when you discover that part of your existing code needs to be moved to async execution.
    • You can simply create a similar future method that wraps your synchronous method like so:

    @future
    static void myFutureMethod(List<String> params) {
    // call synchronous method
    mySyncMethod(params);
    }

    Hope this helps you.

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos