0% found this document useful (0 votes)
14 views

Queueable Batchable Apex in Interview Questions 1729324642

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Queueable Batchable Apex in Interview Questions 1729324642

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Queueable & Batchable Apex in Interview Questions

What is Queueable Apex, and how does it differ from @future methods?

■ Queueable Apex is used for asynchronous processing, similar to


@future but with more flexibility.
■ Unlike @future, Queueable Apex allows for job chaining and can
accept complex data types (e.g., sObjects or custom objects) as
parameters.
■ It also allows you to monitor the job status in the UI, which
@future doesn’t.

How do you enqueue a Queueable Apex job, and what are the limits?

■ You use System.enqueueJob(new MyQueueableClass()) to


enqueue a job.
■ You can queue up to 50 jobs per transaction.
■ Salesforce allows job chaining (up to 50 jobs chained in sequence).

What are the use cases for Queueable Apex?

■ Ideal for processing smaller datasets or complex business logic


asynchronously.
■ Commonly used for job chaining (where one job triggers another).
■ Used when you need to pass complex data types between jobs
(something @future does not support).

N.Veera Raghavamma
Can Queueable Apex be scheduled?

■ Queueable Apex can be scheduled using Scheduled Apex, but it is


not inherently schedulable.
■ You would create a Scheduled Apex class that enqueues the
Queueable job.

How do you monitor Queueable Apex jobs?

■ You can monitor jobs in the Salesforce UI under Setup > Apex Jobs.
■ The Job ID is returned when a job is enqueued, which can be tracked
programmatically.

What is Batchable Apex, and when would you use it?

■ Batchable Apex is designed to process large volumes of data


asynchronously by breaking it into smaller chunks (batches).
■ Use it when processing a large dataset (up to 50 million records)
without hitting Salesforce governor limits.
■ Useful for tasks like mass data updates, recalculations, or report
generation.

Explain the different methods in a Batchable Apex class.

■ start(): Defines the scope of records to be processed, typically


returning a QueryLocator or a list.
■ execute(): Processes each batch of records. Each batch operates in its
own transaction.
■ finish(): Performs post-processing after all batches are processed,
like sending notifications or logging results.

N.Veera Raghavamma
What are the governor limits for Batchable Apex?

■ Batchable Apex can process 200 records per batch by default, but you
can specify a batch size (up to 2,000 records per batch).
■ Each batch operates in its own transaction, meaning governor limits are
reset for each batch.
■ There can be up to 5 concurrent batches running.

How do you monitor Batchable Apex jobs?

■ You can monitor batch jobs in the Salesforce UI under Setup >
Apex Jobs.
■ Each batch is logged separately with its own status, and you can
view details like the number of processed batches.

What is the advantage of using Batchable Apex over Queueable Apex?

■ Batchable Apex is better suited for handling large datasets that


would exceed governor limits if processed in a single transaction.
■ It provides better control over resource consumption, allowing you
to work on records in smaller batches.
■ Queueable Apex is better for smaller jobs and chaining but does
not handle bulk processing as efficiently as Batch Apex.

How would you schedule a Batchable Apex job?

■ You can schedule a Batch Apex job using Scheduled Apex.


■ Implement the Schedulable interface in a class, and in the
execute() method, invoke Database.executeBatch() to run
the batch job.

N.Veera Raghavamma
What happens if a batch fails?

■ If a batch fails (due to unhandled exceptions, governor limits, etc.),


Salesforce retries the batch up to three times.
■ You can implement retry logic in the execute() method or use the
Database.saveResult to track individual record failures within a
batch.

Can Batchable Apex jobs be chained together?

■ Yes, you can chain batch jobs by calling


Database.executeBatch() from the finish() method of a
Batch Apex job.
■ Unlike Queueable Apex, there is no limit to the number of chained
batch jobs, but chaining can impact system resources and job
queue limits.

What are the key differences between Queueable Apex and Batchable Apex?

■ Queueable Apex is more lightweight, better for small-scale


asynchronous processing and chaining, while Batchable Apex is
ideal for bulk processing.
■ Batchable Apex processes data in batches and is more suitable for
large datasets, whereas Queueable Apex handles the whole
process in one go.
■ Queueable Apex allows complex data passing, while Batchable
Apex has more limited parameter options (mainly SOQL results).

N.Veera Raghavamma
What limits do you need to consider when using asynchronous Apex?

■ Queueable Apex: Up to 50 jobs can be enqueued per transaction,


and there can only be 5 jobs actively processing at the same time.
■ Batchable Apex: Can handle up to 50 million records, but there can
only be 5 concurrent batches.
■ Both are subject to the Salesforce async limit, where you can have
up to 250,000 asynchronous Apex executions per 24 hours (or
more, depending on licenses).

N.Veera Raghavamma

You might also like