- What is the advantage of Queueable Apex over future methods? …
- What is the interface used for Queueable Apex? …
- What are methods used in Queueable Apex Class? …
- When will we use future methods instead of Queueable? …
- How many jobs can you chain from executing a job?
Mock interview on Queueable Apex
Interviewee: You can add only one job from an executing job, which means that only one child job can exist for each parent job.
Hey, my name is Saurabh Samir and I am Salesforce Developer. I have been helping to elevate your Salesforce Knowledge. Do comment below if you have any questions or feedbacks.
Interviewer: Can I chain a job that has implemented allowsCalloutsfrom a Job that doesn’t have?
Interviewee: It’s an extension of the Future Methods. It uses the Queueable interface which is an enhanced way of running your asynchronous Apex code compared to using future methods. The limitations which Future methods have, through Queueable Apex, we can overcome them.
Interviewee: Yes, But you’re limited to just one System.enqueueJob
call per execute in the Database.Batchable class. Salesforce has imposed this limitation to prevent explosive execution.
Interviewer: How many numbers of jobs, I can queue using System.enqueueJob() at a time?
The approach is we need to first check how many queueable jobs are added in the queue in the current transaction by making use of Limits class. If the number has reached the limit, then call a schedulable class and enqueue the queueable class from the execute method of a schedulable class.
Interviewee: Similar to future jobs, queueable jobs don’t process batches, so you can’t divide the execution Context. It will process all 200 records, in a single execution Context.
Interviewer: I have 200 records to be processed using Queueable Apex, How Can I divide the execution Context for every 100 records?
Interviewee: You can’t chain queueable jobs in an Apex test. So you have to write separate test cases for each chained queueable job. Also, while chaining the jobs, add a check of Test.isRunningTest() before calling the enqueueJob.
While working on the Salesforce application, we store huge data in our org and it will keep growing year by year. If we have to run some job that will take some time then in the case of synchronous apex we will get the limit error, heap size error, or timeout error. To avoid such issues, we can do those long-running or time-consuming operations using Asynchronous apex which will run in a separate thread and will not impact the main thread. So Asynchronous Apex is used to run the process in a separate thread at a later time.
If we are performing DML on both kinds of sObject in a single transaction, the system doesn’t allow it and throws an exception called Mixed DML exception, stating that a transaction can not have a Mixture of DML operation(Setup and Non-Setup).
No. However, if Scheduled Apex calls a Batch Apex job which then makes a web service callout, the callout will be supported.
Q. 7 Can a future method call another non-future method to process tasks like callouts, and have those methods return data to the future method for further processing?
Since the batch size is 200, so the first batch will be processed completely and all data will be committed to DB. In seconds batch, if we are committing records using normal DML statements like insert, update then the whole batch will be rollbacked. So records 201 to 400 will not be processed.
Advantage of using queueable Apex
Queueable jobs are similar to future methods in that they’re both queued for execution, It has following benefit compared to future methods:
FAQ
What is the use of Queueable apex?
How many records can be processed in Queueable apex?
How many jobs we can queue in Queueable at a time?
Can we call Queueable Apex from future method?