whateveryourscriptis

10 Tips When Creating Batch Apex In Salesforce

By admin January 28, 2014
Blog, Salesforce Development 1

 

Our expert in-house Salesforce developers have put together a list of some best practices and things to keep in mind when creating a batch Apex in Salesforce. The list has been compiled based around observations and overall different things that we feel are important within Salesforce. The following is important to keep in mind when creating a batch Apex in Salesforce.

 

1. To use batch Apex in Salesforce, you have to write an Apex class that implements the Database.Batchable interface. Then invoke the Apex class pro-grammatically.

2. The Database.Batchable interface has three methods that need to be implemented:

A. Start
B. Execute
C. Finish

 

3. Every execution of a batch Apex is a discrete transaction.

 

4. Use the Database.BatchableContext object to track the progress of the batch job.

 

5. All methods in the Database.Batchable interface require a reference to a Database.BatchableContext object. You can only test one execution of the execute method.

 

6. Some important Batch Apex governor limits include:

A. Up to five queued or active batch jobs

B. Batch Apexstart method can have up to 15 query cursors per user open at a time.

C. Batch Apex execute and finish methods have a limit of 5 open query cursors per user.

D. The start, execute, and finish methods can implement up to 10 callouts each.

 

7. When you test batch Apex, you must make certain that the batch job is finished using methods startTest and stopTest around the executeBatch method.

 

8. Methods declared as future can’t be called from a batch Apex class and aren’t allowed in classes that implement the Database.Batchable interface.

 

9. Each time batch Apex is invoked, it creates an AsyncApexJob record. You can use the ID of this record to construct a SOQL query to retrieve the job’s status and progress.

 

10. Apex creates one additional AsyncApexJob record of type BatchApexWorker for internal use for every 10,000 AsyncApexJob records.

 

We hope that the following tips have been helpful to those individuals or developers that are creating a batch Apex in Salesforce. If you have any questions or need any additional help with your Salesforce development, then please feel free to reach out to the team at Mind Digital.

Related Posts