+ Start a Discussion
RonakPatel.ceRonakPatel.ce 

Maximum No. of trigger on one object

Hi,

 

Can anybody tell me that

How many trigger we can make on one object ? 

kiranmutturukiranmutturu

i think there is no limit on number of triggers

ClintLeeClintLee

You might want to consider designing the triggers on your objects to where you have only one trigger per object, and your methods are kept in a separate library class.  This will help keep your logic more manageable and allow you to control the flow of execution on your triggers.  If you have several triggers on the same object there is no guarantee as to what order they will be executed.  

 

For example you might have one trigger on Opportunity that looks like this.

 

trigger OpportunityTrigger on Opportunity( before insert, before update, before delete, after insert, after update, after delete ) {

             

             if( Trigger.isBefore) {

                if( Trigger.isInsert )     OpportunityHandler.beforeInsert( Trigger.New );

                if( Trigger.isUpdate )  OpportunityHandler.beforeUpdate( Trigger.oldMap, Trigger.newMap );

                if( Trigger.isDelete )   OpportunityHandler.beforeDelete( Trigger.Old );

            } else {

               // same concept here for after triggers

           }

}

 

Then, your trigger handler class would look like this.

 

public with sharing class OpportunityHandler {

 

            // Public Methods called by the trigger

  

            public static void beforeInsert( List<Opportunity> trigg ) {

                         doSomething( trigg );

                         doSomethingElse( trigg );

             }

 

            public static void beforeUpdate( Map<Id, Opportunity> oldMap, Map<Id, Opportunity> newMap ) {

                        doSomethingBeforeUpdate( oldMap, newMap );

                        doSomethingElseBeforeUpdate( oldMap, newMap );

            }

 

           // repeat for all trigger contexts //

 

       

           // Private Methods

 

          private static void doSomething( List<Opportunity> opps ) {

                       // do something here 

          }

 

          // add the rest here

}

 

Hope that helps!

 

~ Clint