[SalesForce] trigger design pattern

I was watching some videos on apex best practises and I spotted some discrepancies in advice people give. I wonder how you people code your triggers.

The recommendation is to have one trigger per object that's rather obvious but:
1) Do you keep your logick in one handler class (maybe delegate it to services) passing the trigger context just like here @ around 18 min around 18 mins

2) or do you do it like here @ about 34 min . Keeping the context isolated but doing some preprocessing in the trigger.

I've seen the first pattern a few times and I wonder how bad practice it is (if any)

thanks for sharing your thoughts

Best Answer

Someone will give you a much more detailed answers I an sure but:

The first example Controls the flow of all the processing done on all triggers throughout your org. This is useful in that you have one place to control the flow of your trigger processes. It is building on the second example.

The second example just take that processing out of the trigger and into a class. It is not reusable via other classes so all it is essentially doing is breaking up the code into two separate locations for easier reading / maintenance.

As far as a best practice, implementing the first example would be considered the best practice IMHO.

Related Topic