Salesforce Batch Apex Interview Questions

Questions And Answers 


Company Asked: TCS                                                                                           Experience: 3+ years.

1)What is Batch apex and why we use it. 

Ans:

Batch Apex:

  • Salesforce is introduced a powerful feature that allows developers to process large volumes of data efficiently.
  • Batch apex enables asynchronous processing of large datasets by dividing them into smaller batches.
  • Salesforce-provided interface Database.Batchable to implement the batch apex in our apex class.

Company Asked: TCS, Deloitte                                                                             Experience: 3+ years.

2)What are the methods we have in Batch apex.

Ans:

There are three methods we have in batch apex. 

  • start method.
  • execute method.
  • finish method.

Company Asked: TCS, Deloitte, Salesforce                                                         Experience: 2+,3+ years.

3)Can you please explain me three methods in batch apex.

Ans:

Start() Method:
 
It will execute only once, and it will return scope or records. It will return 50 millions of records.  

Execute() Method:

It will execute each of batch and must have return type void. Each execution of batch will get new governor limits. Default batch size is 200 and maximum size is 2000. 

Example: -
Batch scope: 1000.
Batch size: 200.

No of Times it will execute is 1000/200 = 5 times. 

Finish() Method:

It will execute only once and called after all the batch are processed. Used for post processing.

Company Asked: Salesforce                                                                                     Experience: 3+ years.

4)Can you call one Batch Apex from another Batch Apex in Salesforce?

Ans)

Yes, we can call but some important points need to keep in mind. Those are mentioned below:

Chaining Batch Jobs: You can chain batch jobs by calling another batch job from the finish method of the current batch job. This ensures that the second batch job starts only after the first one completes.

Governor Limits: Be mindful of governor limits, such as the number of batch jobs that can be queued or active at the same time. Salesforce allows a maximum of 5 batch jobs to be queued or active concurrently.

Avoid Recursive Calls: Ensure that your batch jobs do not call each other recursively, which could lead to infinite loops and exceed governor limits.


Feel free to post any comments regarding mistakes, corrections, ideas, and suggestions related to the article.

Thank you for reading the article.

Jayanth A

Comments

Popular posts from this blog

Salesforce Admin Notes

Salesforce Limitations

Salesforce Order of Execution