0

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

2
  • Is Lookup_Field__c and Parent_Object__c and you forgot to replace it? if not, if the Parent_Object__c is changed at the same time as the Lookup_Field__c, which state you would like to check for NY, a) the one the record had before saving or b) the one that it has now? May 10 '20 at 14:13
  • @ Sergio Alcocer "Lookup_Field__c" is lookup to the parent object that means if lookup field changes parent object changes. The formula i have written checks in the new parent record assigned before saving but i want the value of parent record before the change was made and get its "state" field value in a formula field
    – Return0
    May 10 '20 at 14:20
3

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

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.