Book Image

Learning Apex Programming

5 (1)
Book Image

Learning Apex Programming

5 (1)

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

Inside the mind of a trigger


We know that triggers are executed when a DML operation occurs on an sObject record and that they can be executed at two points in the order of execution. All of these details have to be specified in the trigger definition, because triggers can only be executed by the platform itself. There is no way to call a trigger directly and force it to execute. Instead, you will have to write code to perform a DML operation and the Salesforce1 Platform will take care of the rest.

Let's stick with our previous business requirement of keeping the phone field on contact records in sync with the phone field on their respective accounts. To do this, we will start by creating a new trigger. As the trigger will be for DML operations that occur on an account sObject, we will follow the best practice of starting the name of the trigger with the name of the sObject. To keep things simple, we'll just call this new trigger accountTrigger. We can create the new trigger from the Force...