top of page
Your long-standing Salesforce Consultants

How we built a scalable, enterprise-grade Salesforce trigger framework that stopped failures—no more SOQL Errors, Recursion Loops, or Performance Bottlenecks (No Code Version)

  • Writer: Deepak Arora
    Deepak Arora
  • 4 days ago
  • 3 min read

That moment happens to every Salesforce developer: something that worked perfectly for weeks suddenly stops working in production.


It was a little trigger that didn't look dangerous to me.

It worked perfectly...

Until the day it didn't.


This is the story of how a simple trigger led to SOQL limit errors, recursion loops, and bulk-update failures. I then rebuilt everything into a clean, scalable trigger framework that has never failed since.


The Easy Trigger That Became a Mess

It all began with one clean trigger and a class for handling it. But as the organization got bigger, so did the layers of automation:

  • Flow

  • Process Builder

  • Rules for Validation

  • Changes to the workflow

  • Integrations


All of them are changing the same records, which keeps setting off my logic.

This led to:

  • 101 SOQL limit errors

  • 151 DML limit errors

  • Recursive updates

  • Bulk operation failures


A small trigger turned into a nightmare for production.


Attempt #2: Queueable Apex (A Quick Fix)

To ease the pressure on the trigger, I moved logic to a Queueable. It helped, but then it caused more problems:

  • Jobs began to pile up

  • Several jobs changed the same records

  • Updates in real time were delayed

  • It was hard to predict what order the updates would come in.

  • Queueables weren't the answer for the long term.


I needed something that was safe for bulk use, worked at the same time, and was always the same.


The Breakthrough: A Trigger Framework That Is Safe for Recursion

It was clear what the problem was: the same records were being updated over and over in one transaction.


So I rebuilt everything using a structured Trigger Framework that was made to:

  • Keep logic separate

  • Handle Insert/Update/Delete contexts correctly

  • Keep things safe when doing a lot of them at once

  • Protect against recursion

  • Make sure that Flows, PB, and Integrations all behave the same way


How the Final Trigger Framework Looks (in Theory)


One Trigger for Each Object

 No more triggers that happen more than once.

 One trigger sends all logic to a central controller.


Handling Based on Context

 Every event has its own way to clean:

  •  Before Insert

  •  Before Update

  •  After Inserting

  •  After Update

  •  Before Deleting

  •  After Deleting

 Simple to read. Simple to fix.


Layer of Protection for Recursion

A simple but strong idea:

Skip a record if it has already been processed in a transaction.


This got rid of:

  • Loops that go on forever

  • Updates that you don't want to see again

  • Chains that trigger flow

  • Governor limits failures


 Only process the records that need it

The framework only processes the records that really need it, even if 200 records enter the trigger. This lowers the load and keeps the limits from being reached.


Centralized Controller Class

All of the logic is in a special class:

  • Logic to be inserted before in one method

  • Change the logic in another

  • Separate delete logic

 No mixing. No mix-up. Completely modular.


Safe by Default for Bulk

The framework makes sure that:

  • There are no SOQL/DML loops,

  • All operations run on lists, and

  • It can handle large amounts of data.

And governor limits stay happy.


The Result: No Errors Since It Was Put in Place

After switching to this framework:

  • No more SOQL 101 mistakes. No problems with DML limits

  • Recursion loops are gone. Bulk updates went off without a hitch. Debugging got easier

  • The flows, PB, and triggers no longer stepped on each other. Most importantly, the system became predictable.


Final Thoughts

This experience taught me a very important lesson:

Triggers don't fail because they make sense. They don't work because of the way they're set up.


  • A simple trigger might work for now, but as the organization grows, it needs a base that can grow with it.

  • This Trigger Framework, which is safe from recursion and based on events, is now the standard for all of my Salesforce projects.


Clean, easy to scale, and easy to keep up.

And most importantly — limit-proof.



CODE VERSION IS ALSO COMING UP

 
 
 

Comments


bottom of page