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
Narayana Reddy 30Narayana Reddy 30 

On click of "Change" owner trigger validation

Hi,

We would like to have a validation rule on click of Change owner link in record detail page . 
On click of "Change Owner", if the user is not part of two profiles (profile1 and profile2), throw the permission error message . This validation rule should trigger only on click of change login link. Validation rule should not trigger if the owner is getting updated via custom code .  Kindly let us know how to achieve above mentioned functionality 
AbhishekAbhishek (Salesforce Developers) 
Validation rules will fire with single ownership changes

For example going to an account record, clicking on [change] next to the owner field. You will then be presented with the change ownership page. When you attempt to save the ownership change, it will evaluate all validation rules on the account object.

https://help.salesforce.com/articleView?id=000324882&type=1&mode=1

For suggestions check this,

https://salesforce.stackexchange.com/questions/281070/validation-rule-for-edit-the-case-for-specific-profile

https://salesforce.stackexchange.com/questions/215194/prevent-profiles-from-changing-owner-even-if-they-have-edit-rights-to-an-object


Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks.
AnudeepAnudeep (Salesforce Developers) 
Your validation rule should look more or less like this 
 
AND(Owner.Profile.Name <> "Profile1", Owner.Profile.Name <> "Profile2")

To Make Validation Rule bypass if code is run, I recommend reviewing this solution

If you find this information helpful, please mark this answer as Best. It may help others in the community. Thank You!