BESTMassUpdateContactsOnAccountAfter.apex

Image:cookbook.jpg

Force.com Cookbook Sample Code
Chapter 4: Best Practices for Writing Apex - Avoiding Apex Governor Limits

To download all the code samples, access the Cookbook. - Image:Key_icon.gif

This Apex trigger is part of an example that demonstrates several methods for avoiding execution governor limits, including:

  • Making sure that database statements such as insert(), update(), and delete() operate in bulk
  • Using Limits.getDMLRows() for error handling
  • Limiting queries by using static class variables to store query results
  • Testing bulk behavior



trigger BESTMassUpdateContactsOnAccountAfter on Account (after update) {

	List<Contact> contactsForUpdate = MassUpdateContactsHelper.getContactsForUpdate();

	update contactsForUpdate;
}

Sample code provided by salesforce.com. All rights reserved.