The Coding Approach
When deeper customization is needed, the coding approach is a win-win situation. In this chapter, you will learn how Apex triggers can provide complex automation for your processes when a point & click approach is not enough. Also, we will see how to evaluate Visualforce and Lightning Components customizations (which you won’t be required to develop unless you want to learn to be a developer) when user interface constraints require coding magic.
So, in this chapter, we’ll cover the following topics:
- What Apex triggers are and how they are shaped
- The order of execution of automation on the Lightning Platform
- The frameworks that can be used to implement custom user interfaces
Exploring Apex triggers
All the automation we have seen so far is related to rules that are defined to interact with record change events (called DML events, or Data Manipulation Language events). To sum up, these are the topics we’ve already covered in the previous chapters:
- Workflow rules: They execute actions on the originating record (or on its master record) when certain criteria on the originating record applies.
- Approval processes: They define entry criteria that are used to determine whether a record should be further evaluated by approvers (we configure criteria and actions as well).
- Process Builders: Like workflow rules, they are based on record events such as insert and update (but also on platform event creation), but they can execute actions on a wider variety of records (the record itself, its parents, or its children). Also, the kinds of actions available vary from updating a record to launching another Process Builder or an autolaunched Lightning flow.
- Lightning flows: They are used to create complex algorithms without any lines of code and can be launched from a Process Builder, which becomes its triggering criteria, and so the flow is called an autolaunched flow) or can be launched from another Lightning flow. Flows can also be used to create wizards composed of multiple steps to grant user input (but in this case, we can’t talk about process automation but rather in user experience customization).
But what if you need to execute an algorithm involving a complex logic that cannot be executed from the aforementioned tools?
You have two choices:
- Unleash Apex actions from Process Builder or Lightning Flow (which is where Salesforce is going to be in the near future).
- Unleash a complete Apex customization with Apex triggers.
The first approach is limited by how Process Builder/Lightning flow is executed, while Apex triggers deliver more fine-grained control of what’s happening on the database.
Before explaining the pros and cons of Apex triggers (and a quick tour of how to build one, which we’ll hack together), we’ll need to understand a basic concept of automation, the order of execution of automation within the Lightning Platform.