Problem
Business rules had to run reliably as records change, in bulk and on a schedule, and when something broke in production it had to be found and fixed in an org that real users were working in.
What I built
The server-side layer: Apex triggers across objects, batch classes, validation logic, reusable wrapper classes, email-sending logic, Permission Sets and Flows. I also debug production issues across Experience Cloud sites and core orgs.
How it works
The pattern: one trigger per object, logic in a handler. The trigger only dispatches by context. A handler class holds the rules, works on whole collections and never queries or runs DML inside a loop, so it survives a bulk load.
Wrappers for clean contracts. The idea is that reusable wrapper classes give a handler or an LWC a typed, stable shape to read, which decouples them from the sObject layout.
Batch for the heavy work. Batch Apex handles large volumes in chunks, each with its own governor limits.
Permissions as configuration. Permission Sets gate features, so access is a deployable setting rather than a profile hack.
Debugging in production. Debug logs show where limits and DML go. That is the same job the Debug Log Analyzer in the Tools tab of this app does for a pasted log.
trigger CaseTrigger on Case (before insert, before update, after update) {
CaseTriggerHandler h = new CaseTriggerHandler(Trigger.new, Trigger.oldMap);
if (Trigger.isBefore) h.validate();
if (Trigger.isAfter && Trigger.isUpdate) h.notifyOnClose();
}public with sharing class CaseTriggerHandler {
private final List<Case> records;
private final Map<Id, SObject> oldMap;
public CaseTriggerHandler(List<Case> records, Map<Id, SObject> oldMap) {
this.records = records;
this.oldMap = oldMap;
}
public void validate() {
for (Case c : records) {
if (c.Status == 'Closed' && String.isBlank(c.Resolution__c)) {
c.Resolution__c.addError('Add a resolution before closing the case.');
}
}
}
public void notifyOnClose() {
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
for (Case c : records) {
Case before = (Case) oldMap.get(c.Id);
if (c.Status == 'Closed' && before.Status != 'Closed' && c.ContactId != null) {
Messaging.SingleEmailMessage m = new Messaging.SingleEmailMessage();
m.setTargetObjectId(c.ContactId);
m.setSubject('Your case ' + c.CaseNumber + ' is closed');
m.setPlainTextBody('We have closed your case. Reply if anything is still open.');
mails.add(m);
}
}
if (!mails.isEmpty()) Messaging.sendEmail(mails); // one call for the whole batch of records
}
}