9. Batch Processing

You’ve learned two ways you can process database records within the Force.com platform: triggers and Visualforce controllers. Each has its own set of platform-imposed limitations, such as how many records can be created at one time. As you accumulate tens of thousands of records or more in your database, you might need to process more records than permitted by the governor limits applying to triggers and controllers.

Although Salesforce has simplified and incrementally relaxed governor limits in recent Force.com releases, triggers and Visualforce controllers are fundamentally not suited to processing large amounts of data in a multitenant environment. They are driven by user interaction, and must be limited to provide good performance to all users. The Force.com platform carefully controls its resources to maintain high performance for all, so resource-intensive tasks such as processing millions of records must be planned and executed over time, balanced with the demands of other customers.

Batch processing makes this possible, and Batch Apex is the Force.com feature that enables batch processing on the platform. With Batch Apex, data-intensive tasks are taken offline, detached from user interactions, the exact timing of their execution determined by Salesforce itself. In return for relinquishing some control, you, the developer, receive the ability to process orders of magnitude more records than you can in triggers and controllers.

In this chapter, you will learn how to use Batch Apex to create, update, and delete millions of records at a time. It is divided into five sections:

Image Introduction to Batch Apex—Learn the concepts and terminology of Batch Apex, what it can do, and when you should and should not use it.

Image Getting started with Batch Apex—Walk through a simple example of Batch Apex. Develop the code, run it, and monitor its execution.

Image Testing Batch Apex—Like any other Apex code, proper test coverage is required. Learn how to kick off Batch Apex jobs within test code.

Image Scheduling Batch Apex—Although Salesforce has the final say on when Batch Apex is run, you can schedule jobs to run using a built-in scheduler. Learn how to use the scheduling user interface and achieve finer-grained control in Apex code.

Image Sample application—Enhance the Services Manager application by creating a scheduled batch process to identify missing timecards.


Note

The code listings in this chapter are available in a GitHub Gist at http://goo.gl/Iw8XT.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.100.20