5

I have the following logic implemented:

  1. approval process with a field update that set's a datetime on object X to now()
  2. trigger listening to a change of this datetime field on after update. That trigger does some checks on a child object of object X and will change a status of those children.
  3. on object X, I also have a roll-up summary field that get's recalculated based on changes made in step 2 to a status field of the child records
  4. then, there is a workflow that looks at changes in the roll-up summary field to do some further actions

The problem is that the last part (the workflow) is not being triggered. (I don't even see it in my logs)

If I do a manual update to these status fields on the child objects, the workflow IS triggered and I see it in the logs happening too.

Any idea why this could be? When reading through the articles on order of execution, I can't get it why it wouldn't call the workflow. Especially since I read in one of the docs that changes in the roll-up summary field would cause a save on the parent record...

  • Out of curiosity, what is the entry criteria on your workflow? – Mark Masterson Apr 1 '14 at 14:29
  • @MarkMasterson the roll-up field changing from some value to 0. I'm basically checking if there are no child records anymore that have a "pending" status. – KoenVM Apr 1 '14 at 14:31
  • 2
    Was able to reproduce some form of what is going on in a Dev org with the Warehouse package installed. Set an approved time on Invoice, that is updated to now when the record is approved. This sets an after update Trigger to change the status of the Invoice Line Items to complete. A pending Line Items Roll-up on Invoice counts how many pending line items there are. Workflow on Roll-up Summary field set to match criteria every time record is edited checks if Pending Line Items = 0, then updates a No Pending Items checkbox on Invoice – Mark Masterson Apr 1 '14 at 15:41
  • 1
    Results: When going through the approval process, No Pending Items is not set to true. When the line items status is set to complete manually, the workflow triggers from the roll-up summary. Unfortunately I don't have any more time to spend looking at this right now, but I do find the behavior odd. – Mark Masterson Apr 1 '14 at 15:43
  • 1
    I was able to look into it some more, and was able to find this: The Spring '09 Workflow Rule and Roll-Up Summary Field Evaluations update affects the way Salesforce evaluates workflow rules and roll-up summary fields on objects with Apex triggers. The update improves the accuracy of your data and prevents the reevaluation of workflow rules in the event of a recursion. A recursion is a situation in which a part of your custom logic (such as a roll-up summary field or Apex trigger) causes Salesforce to execute the logic twice when saving a record, often resulting in undesirable behavior. – Mark Masterson Apr 1 '14 at 21:38
2

Trigger and Order of Execution Document: https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_order_of_execution.htm

Relevant documentation from the Spring '09 Release Notes: https://na14.salesforce.com/help/pdfs/en/salesforce_spring09_release_notes.pdf

The Spring '09 Workflow Rule and Roll-Up Summary Field Evaluations update affects the way Salesforce evaluates workflow rules and roll-up summary fields on objects with Apex triggers. The update improves the accuracy of your data and prevents the reevaluation of workflow rules in the event of a recursion. A recursion is a situation in which a part of your custom logic (such as a roll-up summary field or Apex trigger) causes Salesforce to execute the logic twice when saving a record, often resulting in undesirable behavior.

This explains why the workflow rule is evaluating when the child objects (and subsequent roll-up summary) are manually updated, but why the workflow is not being reevaluated when the updates are executed through a trigger.

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.