You need to sign in to do that
Don't have an account?
gopal m 14
two triggers
two different programs, two before triggers are there then which one execute first?
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm
http://amitsalesforce.blogspot.in/2015/06/trigger-best-practices-sample-trigger.html
1) One Trigger Per Object
A single Apex Trigger is all you need for one particular object. If you develop multiple Triggers for a single object, you have no way of controlling the order of execution if those Triggers can run in the same contexts
Please let us know if this will help u
So as suggested in the posts above, have one trigger one object. And use apex classes as handlers where all the logic stays. This way you can always re-order your methods in the apex class to control the order.
Example:
My trigger:
Trigger sampleTrigger on Contact(after insert){
ContactTriggerHandler cth = new ContactTriggerHandler();
if(Trigger.isInsert && Trigger.isAfter){
cth.OnAfterInsert(trigger.new);
}
}
And my handler class:
public class ContactTriggerHandler{
public ContactTriggerHandler(){
}
public void OnAfterInsert(List<Contact> newContacts){
// call method 1 :
updateSomeFieldOnAccount();
// call method 2 :
updateSomeFieldOnOtherObjectBasedOnUpdateAbove();
}
}
So in my onafterinsert method above, I am calling two methods - each having some business logic.
So idea is, I want to update some data based on some update I perform on Account. If I have two triggers then it may happen that the one which updates some object data may fire before the one that updates the Account.
In apex, I can re-order my methods as per my requirement and hence this is a much better way of writing triggers.
Hope this helps you :)