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
Jacek DJacek D 

Run workflow depending on update/edit of the object in question, its parent or grandparent?

I am trying to think of a way to run a workflow on a custom object depending on an edit of the object itself, or its parent or grandparent. Meaning, everytime each of those gets updated, the workflow should run.


I tried this forumula using LastModifiedDate as the indicator, but I got an error message.


OR ( LastModifiedDate != priorvalue ( LastModifiedDate ) , 
Campaign_2__r.LastModifiedDate != priorvalue ( Campaign_2__r.LastModifiedDate ) ,
Campaign_2__r.Contract__r.LastModifiedDate != priorvalue ( Campaign_2__r.Contract__r.LastModifiedDate ))

Error: The PRIORVALUE function cannot reference the Campaign_2__r.LastModifiedDate field.


Best Answer chosen by Admin (Salesforce Developers) 
Shashikant SharmaShashikant Sharma

You can not use prior value function with related objects fields, it can only be used with current objects field. It is similar to like in trigger in list trigger.new you can only get values of that object only on which trigger is written not related objects field values. I think to solve your problem you have to write triggers on all three to update a field on this object on which you have this workflow that you want to run each time.

 

1)Create a field on object where you have work flow

2)Use this way , using formula ,only the object on which u have work flow. You can use a trigger also for consitancy.

3)Write trigger on parent and grand parent to update child or grand child  to match the work flow criteria.

 

All Answers

Shashikant SharmaShashikant Sharma

You can not use prior value function with related objects fields, it can only be used with current objects field. It is similar to like in trigger in list trigger.new you can only get values of that object only on which trigger is written not related objects field values. I think to solve your problem you have to write triggers on all three to update a field on this object on which you have this workflow that you want to run each time.

 

1)Create a field on object where you have work flow

2)Use this way , using formula ,only the object on which u have work flow. You can use a trigger also for consitancy.

3)Write trigger on parent and grand parent to update child or grand child  to match the work flow criteria.

 

This was selected as the best answer
Jacek DJacek D

Thanks Shashikant!

 

I will look into building a trigger for those. Can you point me in the direction of those triggers? I have only limited Apex experience.

 

Thanks!

Shashikant SharmaShashikant Sharma

You can start with trigger from this

http://forceschool.blogspot.com/search/label/Apex%20Triggers

 

If any issues you can ask.