2

Just a simple question on best practices - Is it better to combine simple triggers or leave them separate.

For example, I've got a trigger that updates a field based off of another field, and then a second trigger that unchecks a checkbox based on a certain condition.

I know governors come into play with triggers, and I do my best to avoid rubbing up against those limits, but I wasn't sure if they applied to each trigger individually, or as a group.

Thanks! --Lisa

2
  • Its also a royal PITA to try and write test classes for new triggers when there are numerous other existing triggers on the same object! You wind up reviewing extraneous test results from all of the others firing throughout your test class while attempting to debug a problem!
    – crmprogdev
    Commented Jun 26, 2013 at 18:35
  • possible duplicate of General trigger bulkification - best practices Commented Aug 21, 2014 at 18:22

1 Answer 1

6

http://developer.force.com/cookbook/recipe/trigger-pattern-for-tidy-streamlined-bulkified-triggers

The above link is one of the excellent resource i lately read and one should avoid multiple triggers on the same object since that may lead to unnecessary running of code and unnecessary SOQL and DML .Also common practice is to bulkify your triggers and write proper test class to check working of trigger for bulk records .

Maintain a separate helper class for trigger on each object and multiple methods on the helper class depending on logic .

2
  • 3
    I can't agree more -- there is no predictable order of trigger firing if multiple triggers on same object. This was discovered the hard way when triggers executed in one order on sandbox and a different order on PROD. The above pattern is excellent.
    – cropredy
    Commented Jun 26, 2013 at 20:02
  • Hey thanks again for suggesting this method! I'm working on trying to implement it on our sandbox to see what it can do, but I've just got one question - does the actual manipulation of records happen in TriggerFactory.execute() or in the handler classes? (i.e. I want to change the value on a field in an after, and then update all of them at the end) That's the only information I'm not seeing in the example. I know this is probably a really simple confusion, but I'm still learning how this setup works, so my brain just isn't making the connection.
    – Lisa
    Commented Jul 23, 2013 at 19:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .