Salesforce Pluralsight notes
05 Mar 2022
Table of Contents
I need to get rid of some paper at my desk.
I think my notes must be from Play by Play: Adopting Trigger Design Patterns in Existing Salesforce Orgs by Don Robins and Dan Appleman during a free weekend. I know for sure it’s a Dan-on-Pluralsight thing somehow.
Coordinating DML
Dan builds out an Apex class called SimpleLeadUpdater
, and two of its methods are .getLead()
and getLead(Id theId)
.
Principles:
- Never let a trigger handler instantiate (directly or through SOQL) its own SObjects that will eventually be subjected to DML.
- Always access such an SObject’s current state through
.getLeadId(Id)
. - This is something to take care of in your codebase even before you worry about reentrancy control or dependency injection.
Cooperating with declarative
Use custom checkbox fields – or DateTime & “which job’s DateTime is it?” text fields – on objects to let triggers & declarative automations inter-communicate. Bypass_Declarative
, CreatedByDeclarative
, etc.
You might already be familiar with the idea of passing information to automation through custom field values if you have some custom fields that ETL jobs write to, and that automations factor into their decisions.