+ Start a Discussion

every syObject is only one trigger active at sometime?

hi all

I write a apex trriger about a sobject  (for example called 'X'),but  if I want to write another apex trigger (for example called 'X'1)about the same sobject and set them active ,could I test the two apex trigger at the same sobject at the same time ?

I write the apex testing class called 'TestX' and 'TestX1' , can I do it like that?

if can ,please tell me how to set and confige. thank you  wait for your answer....


You can have multiple triggers defined on the same SObject.  However, there is no order of execution guarantee - Trigger 1 might fire before Trigger 2 in sandbox but the reverse in PROD.  Personally, as a best practice, if I need to do multiple functions on a single SObject, say during a Before insert/before update event, I:


  • Write one trigger
  • Use APEX classes/methods to perform each of the operations where the trigger invokes the methods in the order that I need them to execute - thus ensuring consistency of execution across environments
As for your question about testing - a testmethod that does an Insert of SObject X will cause all the before insert and all after insert triggers defined on that SObject to execute.  You are only guaranteed that the before triggers will fire prior to the after triggers.  Your testmethod can do System.asserts on the results of your trigger(s) to verify your software