function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
minciminci 

2 triggers on on sObject - question

Hi.

In my system I have 2 triggers on one Account.

The problem is that I must ensure the one triggers executes first and the seccont just after it.

How can I do it?

Thanks!

 

_Prasu__Prasu_

Simplest solution will be merging both trigger. Or You can make there events different like before and after.

minciminci

I just can't do it because I have 2 triggers that have to act

after an event is fired.

Does salesforce makes enviroment give any promise about which

trigger is executed before and which after? 

Prashant.SakhujaPrashant.Sakhuja

Minci,

You would need to combine your logic of 2 tiggers into one. The logic would be executed in the same sequence in which it is written.

 


Salesforce.com has documented that trigger sequence cannot be predefined. I can remember where I read this though.

 

As a best practice create one trigger per object and use comment blocks to separate different logic blocks.

 

By having all logic in one trigger you may also be able to optimize on your SOQL queries.

Good luck!

 

SteveBowerSteveBower

Or, create a "dispatch trigger".   

 

Change both of your current Triggers into simple classes with an 'execute' method that takes the same arguments as the trigger.   Then write a trigger which invokes the classes in the order you want.

 

It's a reasonable way of having one Trigger for each object, and yet still be manageable by having your code broken out by function.

 

Best, Steve.

minciminci

Tahnk you Guys (or girls)!

I thoyght a bout separating into classes. Of caurse that this solution works.

I just wondered if is there a posibility to schedule manualy triggers.

Thanks!