
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. -
This Apex trigger is part of an example that demonstrates several methods for avoiding execution governor limits, including:
insert(), update(), and delete() operate in bulk
Limits.getDMLRows() for error handling
public class MassUpdateContactsHelper {
//Static variables are local to the context of a Web request
//or testMethod during a runTests call.
//Therefore, we can set this static variable in the before
//trigger when we validate, and insert the proporsed changes
//during the after trigger
private static List<Contact> contactsToRemember = null;
public static void rememberContactsForUpdate(List<Contact> contacts) {
contactsToRemember = contacts;
}
public static List<Contact> getContactsForUpdate() {
return contactsToRemember;
}
}
Sample code provided by salesforce.com. All rights reserved.