Creating the Trigger

Listing 4.42 defines the trigger to validate timecards. It illustrates a best practice for trigger development: Keep the trigger’s code block as small as possible. Place code in a separate class for easier maintenance and to encourage code reuse. Use naming conventions to indicate that the code is invoked from a trigger, such as the Manager suffix on the class name and the handle prefix on the method name.

Listing 4.42 Trigger validateTimecard

trigger validateTimecard on Timecard__c(before insert, before update) {  TimecardManager.handleTimecardChange(Trigger.old, Trigger.new);}

To create this trigger, select File, New, Apex Trigger. Enter the trigger name, select the object (Timecard__c), ...

Get Development with the Force.com Platform: Building Business Applications in the Cloud, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.