Steps to Create an Apex Trigger
An Apex Trigger can be created for any of the Object types.
In this tutorial, we shall learn step by step process to create an Apex Trigger for Contact Object.
To create an Apex Trigger from Salesforce Developer Console, follow the below step by step process.
1. Open Developer Console
Navigate to Salesforce Developer console from Salesforce Login.
2. New Apex Trigger
Click on File menu item. Hover on New in the drop-down list. Click on Apex Trigger.
3. Trigger Name and sObject Selection
Once you click on Apex Trigger, a small pop-up window appears.
We need to provide a name to the Apex Trigger and also select a sObject on which we are going to set the trigger.
Click on Submit.
4. New Apex Trigger Created
A new Apex Trigger is created with the following default code in a new window of Developer Console.
trigger ValidateEmailTrigger on Contact (before insert) {
}
By default, the Apex trigger shall be created for before insert trigger event.
Conclusion
In this Apex Tutorial, we learned to create a new Apex Trigger for a sObject. In our next tutorial, we shall learn how to write Apex Trigger for before insert event.