Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

share|improve this question
    
Is the "Re-evaluate Workflow Rules after Field Change" ticked on the action triggered by the workflow? –  eyescream Nov 12 '12 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 Nov 13 '12 at 0:19
1  
Are you able to post your trigger code to understand what it does? –  techtrekker Nov 13 '12 at 0:44
    
Sure, why not? trigger code –  Jeff Trull Nov 13 '12 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 Dec 13 '12 at 20:25
show 8 more comments

2 Answers

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.

share|improve this answer
    
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 Dec 26 '12 at 5:56
add comment
up vote 0 down vote accepted

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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