0

I have a question regarding the execution order of Trigger, Workflow and Process. I know there are plenty of resource there but none of them match my case.

Right now our project have bunch of trigger logic, workflow and process are being used upon the Case object. According to this post, process will be executed after workflow(#12 and #13) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm?search_text=order

I was wondering:

  1. Since the workflow's update fields will fire another round of UPDATE trigger, if the UPDATE trigger is occurred before or after process?And which values(old or new) should be taken into account when process is executed.
  2. How can we determine a UPDATE trigger is fired from Salesforce UI, SOAP API, workflow or process? I would like to add some logic inside UPDATE trigger to detect the source of the update request.
0

I can only confidently answer your second question.

There is no way to tell what the source of any DML operation is. An update is an update, no matter what initiated it. Salesforce does not give us any built-in tools to be able to determine this.

There is some wiggle room in there though.

If, for example, you have a connected app to allow a third party to access your org, and you have one user that is only used by this one connected app, then you could reasonably say that a particular update originated from an API call (via this connected app) if you check that UserInfo.getUserId() equals the Id of this particular user.

That is, I hope you can see, quite a cumbersome set of requirements, and it's not easy to enforce them. Trying to scale such a solution up would be immensely complex and painful.

If what you're trying to do relies on being able to distinguish between the sources of DML operations, I'd urge you to take some time to rethink your approach.

0

Answer to your first question: 1. Update trigger runs before Process and if Process has field update, it again goes through save procedure i.e. trigger, workflow and so on. In the entire save process (does not matter how many times it is repeating) old values always will be the initial value from where process started and new value will be the value user trying to update.

Answer to second question: You can do that by creating field on custom object. On start of each process you can set that field to store the source of the DML and at the end you reset it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.