You need to sign in to do that
Don't have an account?
Raj R.
Does a workflow field update run before an apex trigger?
Hi,
I wanted to see if a workflow field update runs before an apex trigger (after update)?
Scenario:
I have a certain set of campaigns that when they are updated, I want to create events associated to those Campaigns. I am using an apex trigger to create the events, but I wanted only update those events when two Campaign fields are updated (StartDate and customField1). This means that if other campaign fields are updated then i do not want to update the events.
I was thinking of using a workflow field update using the following logic to determine whether the apex trigger should update the events.
Then in my apex trigger, I would check if Campaign.UpdateEvents__c = TRUE, then only update the Events using the following logic below:
Then once the events have been updated, I would like to set the Campaign.UpdateEvents__c to FALSE.
I was wondering if all this was possible and if the workflow field update would process before the apex trigger.
I wanted to see if a workflow field update runs before an apex trigger (after update)?
Scenario:
I have a certain set of campaigns that when they are updated, I want to create events associated to those Campaigns. I am using an apex trigger to create the events, but I wanted only update those events when two Campaign fields are updated (StartDate and customField1). This means that if other campaign fields are updated then i do not want to update the events.
I was thinking of using a workflow field update using the following logic to determine whether the apex trigger should update the events.
Workflow criteria: ISCHANGED(StartDate) AND customField1=TRUE Field update (set UpdateEvents__c field to true): Campaign.UpdateEvents__c = TRUE
Then in my apex trigger, I would check if Campaign.UpdateEvents__c = TRUE, then only update the Events using the following logic below:
//assume cmps is all the campaigns being updated List<Campaign> cmps = [Select Id, StartDate, UpdateEvents__c From Campaign]; for(Campaign cp : cmps) { if(cp.UpdateEvent__c = true) { //logic to update events associated to the campaign goes here }//end if }//end for
Then once the events have been updated, I would like to set the Campaign.UpdateEvents__c to FALSE.
I was wondering if all this was possible and if the workflow field update would process before the apex trigger.
The order of execution (with Apex) is as follows:
1. All before triggers execute
2. System validation occurs, such as verifying that all required fields have a non-null value, and running any user-defined
validation rules
3. All after triggers execute
4. Assignment rules execute
5. Auto-response rules execute
6. Workflow rules execute
7. Escalation rules execute
8. Post-commit logic executes, such as sending email
As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.
Thanks
All Answers
The order of execution (with Apex) is as follows:
1. All before triggers execute
2. System validation occurs, such as verifying that all required fields have a non-null value, and running any user-defined
validation rules
3. All after triggers execute
4. Assignment rules execute
5. Auto-response rules execute
6. Workflow rules execute
7. Escalation rules execute
8. Post-commit logic executes, such as sending email
As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.
Thanks
Hi rRup,
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm
Thank you for your responses. That clarifies a lot.
it looks like i cannot do this the way i wanted to. What do you think would be the best way to check if the the start date value changed in a trigger.?
There is not really a "ISCHANGED(field)" in apex trigger, so I am wondering what would be the equivalent in apex trigger.
Hi rRup
If you are in the Trigger then you can try the below code to trace if startDate is updated and customField1 is True.
Feel Free to ask If you have any question regarding this.
Thanks,
799 Coder