[SalesForce] Prior Value in validation rule to find previous lookup field value

There is a look up relation between 2 objects. Parent object has picklist field "State".The requirement is to create validation rule on child object to throw error if lookup field is changed and the previous parent the lookup was pointing to has state field as "NY".The validation rule i came up with is this

AND( ISPICKVAL(Parent_Object__r.State__c , "NY"),ISCHANGED( Lookup_Field__c ) )

but the error gets thrown if the lookup value is changed and new lookup value has state field as "NY".The requirement is to check if previous Parent the lookup was pointing to before changing lookup field and check if its State field was "NY".
I am aware of PRIOR value function but not sure how to use it to get prior value of lookup.
How can that be achieved

Best Answer

If I understand you correctly, you have 2 objects, and the Lookup from the child to the parent is called Lookup_Field__c.

If that is the case, an easy way to achieve what you are looking for would be to

  1. create a checkbox formula field in your child object Parent_Object_Protected_State__c that references the value you want to check (ISPICKVAL(Lookup_Field__r.State__c,'NY'))
  2. Use the validation Rule AND(ISCHANGED(Lookup_Field__c), PRIORVALUE(Parent_Object_Protected_State__c))

You could as an alternative create a text formula field and check the state in the validation rule, but then you will have to play with TEXT() function