queueable apex interview questions

Interview Question on Queueable Apex
  • 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:

  • Getting an ID for your job: When we submit our job by invoking the System.enqueueJob method, the method returns the ID of the new job. This ID corresponds to the ID of the AsyncApexJob record. We can use this ID to identify job and monitor its progress, either through the Salesforce user interface in the Apex Jobs page, or programmatically by querying your record from AsyncApexJob.
  • Using 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.
  • 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 processing that depends on another process to have run first.
  • FAQ

    What is the use of Queueable apex?

    Take control of your asynchronous Apex processes by using the Queueable interface. This interface enables you to add jobs to the queue and monitor them. Using the interface is an enhanced way of running your asynchronous Apex code compared to using future methods.

    How many records can be processed in Queueable apex?

    The difference between queueable and Batch Apex (which all belong to asynchronous Apex), is that you would use Batch Apex whenever you are processing a larger number of records compared to queueable. Batch Apex jobs are limited to five tasks running simultaneously, whereas queueable jobs can run up to 100!

    How many jobs we can queue in Queueable at a time?

    However, keep in mind that you can add only up to 50 jobs within a single transaction. Another huge benefit of Queueable Apex is the ability to chain jobs in a sequence. You can chain one queueable job to another by starting the second job from a running job. There are no limits on the depth of chained jobs.

    Can we call Queueable Apex from future method?

    Future methods cannot be monitored, but queueable apex can be monitored using the job id which is returned by System. enqueueJob() In execution cycle, you cannot call from one future method to another future method. Its achieved inqueueable class by using the Chaining Jobs.

    Related Posts

    Leave a Reply

    Your email address will not be published. Required fields are marked *