7

I have a Lookup relationship from Contact to a custom object, and an "after update" trigger on Contact that deletes any of those related objects that no longer have children. There is a workflow rule on Contact that references fields from the parent object. I find that when I change the related object - i.e., reparent the Contact - and the old parent is deleted by the trigger, the save fails with the following error message:

The formula in the "TestRelatedWorkflow" rule or process is invalid due to the following: The record you attempted to access has been deleted

It seems to me that the workflow rule should be referencing the new (updated) parent object and its fields, not the old (deleted) parent. I read the trigger order of execution document carefully, and it seems to indicate that workflow rules should be evaluated after all triggers. Am I missing something? Is there a sensible workaround?

Update: this is now filed as case 09012899

13
  • Is the "Re-evaluate Workflow Rules after Field Change" ticked on the action triggered by the workflow?
    – eyescream
    Commented Nov 12, 2012 at 23:49
  • It wasn't, but it is now. No change in behavior. It looks like that box relates to the re-evaluation of workflow rules when you change a field as a result of a workflow action, and not to the evaluation of the rule itself.
    – Jeff Trull
    Commented Nov 13, 2012 at 0:19
  • 1
    Are you able to post your trigger code to understand what it does? Commented Nov 13, 2012 at 0:44
  • Sure, why not? trigger code
    – Jeff Trull
    Commented Nov 13, 2012 at 1:07
  • 1
    Hi Adam, the code is linked to in the comment two above yours, from November 13... Would be delighted to have some help on this if you have ideas.
    – Jeff Trull
    Commented Dec 13, 2012 at 20:25

2 Answers 2

1

The workflows fire after the triggers, but if there are any field updates that do change the values the triggers are fired again. So the triggers could run before and after workflows. Maybe use some static variable to determine if this is the first time or the second time the triggers fire.

1
  • Thanks for your comment, Andres. However, the issue is occurring during workflow rule evaluation. The rule appears to see a situation where the parent object has been deleted. However, the parent object is only deleted because the child now points to a different parent. So an intermediate state, where the child refers to a deleted parent, should never be visible to a workflow rule or anything else.
    – Jeff Trull
    Commented Dec 26, 2012 at 5:56
0

As of Winter 14 (or perhaps Spring or Summer 13) this issue is no longer reproducible and thus the question is moot.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .