rules repository

A-3060 Always define a primary key column for editable Interactive Grids.

Severity Error Check + SQL-based Test Free New

Reason

An editable Interactive Grid needs at least one column marked as Primary Key so APEX can identify each row for update and delete operations. Without a primary key column, DML on the grid fails at runtime.

Mark the identifying column(s) as Primary Key in the column's Source settings.

Examples

Non-Compliant Example

page 10 (
    // ...
    region employees (
        name: Employees
        type: interactiveGrid
        // ...
        edit {
            enabled: true
            allowedOperations: [
                add
                update
                delete
            ]
        }
        // ...
        column EMPLOYEE_ID (
            // ...
            source {
                databaseColumn: EMPLOYEE_ID
                dataType: number
                // no primaryKey -> defaults to false
            }
        )
    )
)
Issues
LineColumnMessage
813Editable Interactive Grid has no primary key column defined.

Compliant Solution - ★★★★★

page 10 (
    // ...
    region employees (
        name: Employees
        type: interactiveGrid
        // ...
        edit {
            enabled: true
            allowedOperations: [
                add
                update
                delete
            ]
        }
        // ...
        column EMPLOYEE_ID (
            // ...
            source {
                databaseColumn: EMPLOYEE_ID
                dataType: number
                primaryKey: true
            }
        )
    )
)

Column EMPLOYEE_ID is defined as primary key

Compliant Solution - ★★★★★

page 10 (
    // ...
    region employees (
        name: Employees
        type: interactiveGrid
        // ...
        // no edit 
        // ...
        column EMPLOYEE_ID (
            type: hidden
            // ...
            source {
                databaseColumn: EMPLOYEE_ID
                dataType: number
            }
        )
    )
)

Read-only Interactive Grids don't need a primary key column

Tests

Test SQL query

select aa.workspace || '.' || aa.alias || '.' || r.page_id || '.' || r.region_name as identifier,
       'Editable Interactive Grid ' || r.region_name || ' in page ' || r.page_id
         || ' of app ' || aa.alias || ' in ' || aa.workspace
         || ' has no primary key column.' as message
  from apex_application_page_regions r
  join apex_applications aa
    on aa.application_id = r.application_id
       and aa.workspace = r.workspace
  join apex_appl_page_igs ig
    on ig.region_id = r.region_id
 where ig.is_editable = 'Yes'
   and not exists (select 1 from apex_appl_page_ig_columns c
                    where c.region_id = r.region_id and c.is_primary_key = 'Yes')
   and aa.workspace in (#ApexWorkspaces#)

Test results

IdentifierMessageMigration
WORKSPACE.CUSTOMERS.10.EmployeesEditable Interactive Grid Employees in page 10 of app CUSTOMERS in WORKSPACE has no primary key column.-

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