Book Image

Learning Apex Programming

Book Image

Learning Apex Programming

Overview of this book

Table of Contents (17 chapters)
Learning Apex Programming
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Bigger, better, and batchier


The Database.Batchable interface can be a lifesaver when dealing with large datasets. As there is a limit on the number of callouts that can occur in a single transaction, the Batchable interface is often used to sync data with outside systems. In order to perform a callout from an implementation of the Database.Batchable interface, you need to make a small tweak to your class definition. In addition to implementing the Database.Batchable interface, you must also implement the Database.AllowCallouts interface, shown as follows:

//Apex Class that implements the Batchable interface
global class contactBatch implements Database.Batchable<SObject>, Database.AllowCallouts {
  ...
}

Your code to perform callouts can occur in the start(), execute(), and finish() methods. The exact number of callouts allowed is specified in Salesforce Limits Quick Reference Guide located at https://login.salesforce.com/help/pdfs/en/salesforce_app_limits_cheatsheet.pdf. At the time...