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
CliffordClifford 

Order of execution of a Trigger and Workflow Rule

I have a custom object.  When a Task is added to the custom object I need to do two things.  1. Check the subject of the Task.  If it is a certain value, I have to update the parent custom object status field.  2. I also need to call an external web service if the custom object status field has been updated to a particular value. 
 
I am not able to update the custom object status field using a work flow rule since the logic is dependent upon the Task object.  Because of this I have a trigger and Apex class that updates the custom object status based on the Task subject.  I then want to use a work flow to check the custom object status and if the status meets the criteria to send an asynchronous outbound message.  I would like to use a work flow to send messages asynchronously.
 
Problem - the work flow runs before the trigger, so even if the trigger updates the status to a value that would make the work flow rule evaluate to true, the work flow runs AFTER the trigger.
 
Questions:
1. Is there a way to change the order of execution for the trigger and work flow?
2. Can I call a work flow from a trigger or Apex class?
3. I know I can make a synchronous call to a web service from an Apex class, but aside from a work flow is there another way to make an asynchronous call?
 
Thanks in advance.
 
Cliff


Message Edited by Clifford on 05-13-2008 09:09 AM
werewolfwerewolf
1. Is there a way to change the order of execution for the trigger and work flow?

Nope.  The triggers always run before workflow.

2. Can I call a work flow from a trigger or Apex class?

You kind of can -- if you touch a different object that triggers workflow on it.  But not on the exact same object, since by then you're already in the execution chain for that object.

3. I know I can make a synchronous call to a web service from an Apex class, but aside from a work flow is there another way to make an asynchronous call?

Not yet, but I believe it's coming soon in a future release.
werewolfwerewolf
Also, can you rig your web service receiver to take a synchronous call from Apex SOA very quickly and then noodle on it itself?  That's one possible workaround.
CliffordClifford
Thanks for the info, I appreciate it.  That is a good idea to have a quick release synchronous service to not block the SFDC calling process...I will certainly look into that.