[SalesForce] How to add Validation rule for whatid

I have a requirement in which for Inactive accounts if user try to edit or create a new task then it should not allow user to save the task. It should throw some validation message.
On the task object there is a field 'Related To' which gives me All the accounts but I can not apply filter criteria for this kind of field.SO I am trying to write a validation rule on task which should throw an error message when the account status is inactive.
I am trying to write like this:

OR(whatid!=null,Account.Inactive=true)

but in the validation rule I am not able to find Account.

Is there any way where I can get the Inactive field value so that I apply it in validation rule?

Or I have to do coding in this scenario. Please suggest

Best Answer

You cannot reference the related Account's fields while writing a validation rule on the Task. The Task object WhatID is polymorphic which means it could be refer to several objects. On the whatid at least you cannot reference related fields like you can with ownerid which is polymorphic as well

The only reliable option will be to make use of an Apex Trigger that prevents the creation of the Task.

Related Topic