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
CooldayCoolday 

I have a requirement where I have to create a validation rule - There is an object opportunity (Master) and a custom object

I have a requirement where I have to create a validation rule - There is an object opportunity (Master) and  a custom object (Detail). Whenever stage is Qualification on opportunity then I have to lock 3 fields from editing  Field 1 , Field 2 and Field 3. Field 1 is on opportunity object and Field 2 and 3 are on custom object. 

I created the validation rule on custom object -

AND( ISPICKVAL(ISPRIORVAL( Opportunity__r.StageName) , 'Qualification') ,
 OR(
ISCHANGED( Opportunity__r.Field1 )
 ISCHANGED( Field2 ) ,
  ISCHANGED( Field3 ),
 )
)
I am getting this error -
The PRIORVALUE function cannot reference the field (ISPRIORVAL( Opportunity__r.StageName) validation rule.

Also, We do not have any lookup on opportunity to custom object so I had to create the validation rule on Custom Object.

Best Answer chosen by Coolday
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

One small correction I forgot to add.

You cannot use Priorvalue on releted objects.
AND( ISPICKVAL(  Opportunity__r.StageName, 'Qualification'),
 OR(
 ISCHANGED( Field2 ),
 ISCHANGED( Field3 )
 )
)


Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

You may have to write two validation rules for this. One on Opportunity object and other on the child object. The validation should not use ISPRIORVAL in child object because we cannot channge the opportunity and the child object at same time. So the validation rule would be as below.

On Opportunity:
 
AND(ISPICKVAL( PRIORVALUE(StageName), 'Qualification')
, ISCHANGED( Field1 ))

On custom object.
 
AND( ISPICKVAL( PRIORVALUE(Opportunity__r.StageName), 'Qualification' ,
 OR(
 ISCHANGED( Field2 ) ,
  ISCHANGED( Field3 ),
 )
)

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
CooldayCoolday
The one created on Custom object still shows this error -

 The PRIORVALUE function cannot reference the Opportunity__r.StageName field.

This is my validation rule on Custom Object

AND( ISPICKVAL( PRIORVALUE( Opportunity__r.StageName), 'Qualification'),
 OR(
 ISCHANGED( Field2 ),
 ISCHANGED( Field3 )
 )
)
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

One small correction I forgot to add.

You cannot use Priorvalue on releted objects.
AND( ISPICKVAL(  Opportunity__r.StageName, 'Qualification'),
 OR(
 ISCHANGED( Field2 ),
 ISCHANGED( Field3 )
 )
)


Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
This was selected as the best answer
CooldayCoolday

It works !

Thank you so much Sai Praveen.