rules repository

A-1860 Avoid NOT NULL validations; use the item's Value Required setting.

Severity Warning Check + SQL-based Test Free New

Reason

A separate Item is NOT NULL validation duplicates what the item's built-in Value Required setting already does. The built-in setting is simpler, shows the required indicator automatically, and is what the APEX upgrade utility keeps; standalone NOT NULL validations are redundant maintenance overhead.

Enable Value Required on the item and delete the standalone NOT NULL validation.

The exception is an item that is only required in certain cases, for example an email address that is required only when the contact method is Email, or a field that must be filled on Submit but not on Save Draft.

Examples

Non-Compliant Example

page 10 (
    // ...
    pageItem P10_NAME (
        type: textField
        // ...
    )

    validation p10-name-required (
        name: P10_NAME must be entered
        execution {
            sequence: 10
        }
        validation {
            type: itemIsNotNull
            item: P10_NAME
        }
        error {
            errorMessage: Name is required
            associatedItem: @P10_NAME
        }
    )
)
Issues
LineColumnMessage
1419Validation uses a NOT NULL validation; use the item's Value Required setting instead.

Compliant Solution - ★★★★★

page 10 (
    // ...
    pageItem P10_NAME (
        type: textField
        validation {
            valueRequired: true
        }
        // ...
    )
)

Compliant Solution - ★★★★★

page 10 (
    // ...
    pageItem P10_CONTACT_METHOD (
        // ...
    )

    pageItem P10_EMAIL (
        type: textField
        // ...
    )

    validation p10-email-required (
        name: P10_EMAIL required for contact method email
        execution {
            sequence: 10
        }
        validation {
            type: itemIsNotNull
            item: P10_EMAIL
        }
        error {
            errorMessage: Email is required when the contact method is Email
            associatedItem: @P10_EMAIL
        }
        serverSideCondition {
            type: item=value
            item: P10_CONTACT_METHOD
            value: EMAIL
        }
    )
)

It is fine to use a Item is NOT NULL validation if it is conditional.

Tests

Test SQL query

select aa.workspace || '.' || aa.alias || '.' || vl.page_id || '.' || vl.validation_name as identifier,
       'Validation ' || vl.validation_name || ' in page ' || vl.page_id
         || ' of app ' || aa.alias || ' in ' || aa.workspace
         || ' uses a NOT NULL validation; use the item''s Value Required setting instead.' as message
  from apex_application_page_val vl
  join apex_applications aa
    on aa.application_id = vl.application_id
       and aa.workspace = vl.workspace
 where vl.validation_type_code = 'ITEM_NOT_NULL'
   -- conditional validations are legitimate: Value Required cannot express "required only when …"
   and nvl(vl.condition_type_code, 'ALWAYS') = 'ALWAYS'
   and vl.when_button_pressed_id is null
   and aa.workspace in (#ApexWorkspaces#)

Test results

IdentifierMessageMigration
WORKSPACE.CUSTOMERS.10.P10_NAME must be enteredValidation P10_NAME must be entered in page 10 of app CUSTOMERS in WORKSPACE uses a NOT NULL validation; use the item's Value Required setting instead.-

Parameters

Use parameters to customize the rule to your needs.

ParameterDescriptionDefault Value
ApexWorkspacesComma-separated List of APEX workspaces owning APEX applications to check.dblinter, dbl_gui

References