Providing an Expression to Make a Custom Field Conditionally Required
A custom field can be optional or required. By default it is optional. Alternatively, you can configure a conditionally required expression.
If you do this, it is evaluated each time a page displaying the field is rendered or
refreshed, as well as when the object is validated. The expected return type of the
expression boolean
. If you define one for a field, you must also
configure the Depends On list to indicate the names of any fields on which your
conditionally required expression depends. By doing this, your conditionally required
field will interactively show or hide the visual indicator of the field's being required
as appropriate when the user changes the values of fields on which the conditionally
required expression depends.
For example, consider a custom TroubleTicket
object with
Priority
and Justification
fields. Assume that
priority is an integer from 1 to 5 with priority 1 being the most critical kind of
problem to resolve. To enforce that a justification is required for trouble tickets
whose priority is 1 or 2, configure the conditionally required expression for the
Justification
field as follows:
Priority_c <= 2
After configuring this expression, you must then indicate that the
Justification
field depends on the Priority
field
as described in Understanding When to Configure Field Dependencies.
This ensures that if a trouble ticket is created with priority 2, or an existing trouble
ticket is updated to increase the priority from 3 to 2, that the
Justification
field becomes mandatory.