3

future method behaviour -

1. is executed in their own thread
2. do not start untill resource are available
3. future callout gives us 200 asynchronous soql limit.

Why we use Queueable Apex and in which scenario ?

can i have a proper clarification.

Thanks Nirmallya Ghosh

  • main reasons - can chain them and camn pass any data structure to Queuable compare to future which is pretty limited in parameters it can accept – Kaushik Ray Mar 3 '16 at 11:36
5

This is broad questions but let me try to give you summery

1) You can pass Array of objects to Queueable in future you can not.
2) You can chain jobs in Queueable in future you can not.

Ex. You are calling API X and on success you are calling API Y with result of first call(X) this you can do easily in Queueable

3) Queueable is seen as combination of Future & Batch but future is just future

From SFDC documentation:

  1. JobID is generated on submission of an asynchronous job. This JobID can in turn be used to programmatically query the status of the job via the 'AsyncApexJob' table. Alternatively, the job can be monitored via the UI (Setup->Monitoring->Apex Jobs)

  2. Asynchronous jobs submitted via the Queueable Interface can be chained, this means that you can add a job to the queue, and add a new job to the queue once the previous job has completed, something that was not possible via Future Methods https://help.salesforce.com/apex/HTViewSolution?id=000204563&language=en_US

EDIT 1

Much better explanation and actual example with code is available here https://developer.salesforce.com/blogs/developer-relations/2015/05/queueable-apex-future.html

| improve this answer | |
  • Ok Thanks. Is there any example available which we can do through queueable apex but not through future. – Nirmallya Ghosh Mar 3 '16 at 13:05
  • check my updated answer – AtulRajguru9 Mar 4 '16 at 4:21
  • thanks for detailed post. Does separate asynch limit apply for each queue member ? ie job 1 got its own limit and then job 2 got new limit (ie its own limit) ? – Chirag Mehta Feb 8 '17 at 8:02
  • Yes, we get new set of its own limits in every job. – AtulRajguru9 Oct 17 '19 at 5:17
2

In the case of Apex processes that run for a long time, such as extensive database operations or external Web service callouts, you can run them asynchronously by implementing the Queueable interface and adding a job to the Apex job queue.

In Queueable interface methods, some governor limits are higher than for synchronous Apex, such as heap size limits.

Also in Queueable interface methods, No limit is enforced on the depth of chained jobs, which means that you can chain one job to another job and repeat this process with each new child job to link it to a new child job. For Developer Edition and Trial organizations, the maximum stack depth for chained jobs is 5, which means that you can chain jobs four times and the maximum number of jobs in the chain is 5, including the initial parent queueable job.

| improve this answer | |

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.