+ Start a Discussion
deepakMdeepakM 

Share common code in triggers ?

HI 

 

we have some common functionlity in triggers on different objects.like:

 

trigger 1

{

 

      if(aa="qwe")

       {

              xyz ="sss";

 

        }

}

trigger 2

{

 

      if(aa="qwe")

       {

              xyz ="sss";

 

        }

}

trigger 3

{

 

      if(aa="qwe")

       {

              xyz ="sss";

 

        }

}

 

 

but operate on different objects.

 

so is thr any way that block of code start from if will place somewhere else and we just refere that  in triggers..so in case any change ,will be done on that and reflect in all the triggers

 

thanks 

 

 

mohimohi

you may create a method in class ,put that code in method block , call that class in trigger.

 

 

hope this will help you, if it is a insight for your problem please mark it as accepted.

Navatar_DbSupNavatar_DbSup

Hi,


You can simply define that method inside the class and create the instance of class inside the trigger. Now call that method through the instance. Try the below code as reference:


public class TestCall4mTrigger
{
public void justCheck(string st)
{
system.debug('@@@@@@@@@@@@@@@' +st);
}
}
/////////////////////// Trigger //////////////////////////
trigger TaskCreate2 on Task (after Insert)
{
TestCall4mTrigger te=new TestCall4mTrigger();
te.justCheck('Ashish Test');
}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.