In this section, we are going to get started with developing Apex triggers.
This will allow you to experience a whole new world of possibilities in customizing the Salesforce platform.
However, I want you to keep in mind writing code on the Salesforce platform should always come as a last resort. I’ve been working on the Salesforce platform for the past 5 years, and I deal with Apex code almost every day, but I never use Apex when the solution can easily be implemented with Salesforce’s declarative tools.
These are principles that you should even take into consideration when you do have to write Apex code. For example, if 90% of what you want to do can be done inside a Flow, but that remaining 10% can only be done in Apex, you can create a Flow and call Apex using an invocable action, giving you the best of both worlds. Even writing your code to be as re-usable by other code as much as possible makes good use of this practice, and is a standard practice in traditional development as well.
That being said, I’m going to have to break these rules a little bit when teaching the fundamentals of Apex development in order to help get these concepts across. But these are still essential rules to keep in mind when developing on the Salesforce platform in the real world.
So without any further delay, let’s jump right in to developing triggers.
In this lesson, we create a basic Apex trigger.
In this lesson, we look at the different trigger types and contexts, such as:
Before Insert
After Insert
Before Update
After Update
Before Delete
After Delete
Resource:
Triggers and Order of Execution - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order...
In this short lesson, I cover some Salesforce Trigger Best Practices, such as:
One Trigger per Object
Keep Triggers Logic-less
Control Triggers with Declarative Functionality