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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.199.182