Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /home1/oijoiv2f/public_html/wp-content/themes/entaro/template-posts/single/inner.php on line 23

Batch class : Salesforce Interview Question

Salesforce Interview Question on Batch class

What is Batch Apex?

It is a class which is capable of accepting records in bulk and then depending upon the batch size the group of records are broken into Batches and are processed asynchronously.

When should we use a batch class?

We should batch apex when we are dealing with records in bulk mainly the record size above 10000 and cannot be handled by the normal DML operations.

What is the basic structure of a Batch class?

the basic structure of a batch consists of three methods:

  1. Start
  2. Execute
  3. Finish

Describe each method of a batch class?

Start method:

Syntax: global Database.QueryLocator start(Database.BatchableContext BC)

This method receives the batchable context variable as an argument and returns a query locator variable.

Execute method:

Syntax:  global void execute(Database.BatchableContext BC, List<Account> scope)

This method receives the batchable context variable and an additional argument as scope which of list of subject type we are working with.

Finish method:

Syntax: global void finish(Database.BatchableContext BC)

This method receives the batchable context variable and is the last method which gets executed after all the batches have been processed, we can perform all the post execute logic in this method like sending an email etc.

What is a scheduler class?

A scheduler class implements the Schedulable interface and have to implement its execute method.

how to schedule a batch class ?

there are two ways to schedule a batch class:-

  1. Using developer console
  2. Using System Scheduler

By Developer console we have to pass a cron variable like below:-

AScheduleClass A = new AScheduleClass();

String schedule =  ’20 30 8 10 2 ?’; // cron object

String jobID = system.schedule(‘Merge Job’, schedule, A);

Via System Scheduler:

  1. Go to setup and in quick search bar type schedule. Then click on schedule apex.
  2. Select schedule created and set the time with help of the Salesforce UI.

Can we call a batch class from another batch class?

Yes, we can call one batch class from another batch class but only if it is called from its finish method.

Can we call a Future method from batch class?

no, we cannot directly call a future method from a batch class.

What is Database.Stateful used for in batch class?

As batch class runs asynchronously, to maintain the state of a variable across each batch we implement Database.Stateful.

How many can concurrent batch jobs be added to the queue?

At most, there can be 5 bath jobs queued at a time.

How can we track the status of the current running batch job?

The job Id returned by the batchable context variable helps us in finding the status of a batch through AsyncApexJob.Status.

Q . What is the purpose of start method in Batch Class?

Start object returns the list or group of records on which we are going to make changes.

What is database.getQuerylocator and what are its advantages?

It is used to fetch records from the database, if used in batch class it can fetch up to 50 millions records.

******* More questions to come

Want to learn more about batch Classes and Asynchronous Apex have a look at link below

Asynchronous Apex

Sumit Datta

Sumit Datta

I am a 5x Certified Salesforce developer with overall 7 years of IT experience and 5 years of Implementation experience in Salesforce. I am here to share my knowledge and help Beginners in Salesforce to understand the concepts of Apex, Visualforce, Salesforce Lightning and Salesforce Configuration.

8 Comments

  1. […] Relationship Map *** more Salesforce projects to be uploaded soon. Salesforce interview questions on Batch Class | SalesforceNextGen. Salesforce Interview Question on Batch class What is Batch Apex? It is a class which is capable of […]

  2. […] Batch class : Salesforce Interview Question […]

  3. […] 6. Salesforce Interview Questions Batch Class  […]

  4. […]      6. Salesforce Interview Questions Batch Class  […]

  5. […]      6. Salesforce Interview Questions Batch Class  […]

  6. […]      6. Salesforce Interview Questions Batch Class  […]

  7. […]      6. Salesforce Interview Questions Batch Class  […]

  8. […]      6. Salesforce Interview Questions Batch Class  […]

Leave a Comment

Your email address will not be published.