Method declares two or more Boolean parameters

ID

apex.maintainability.multiple_bool_parameters

Severity

info

Remediation Complexity

medium

Remediation Risk

medium

Remediation Effort

medium

Resource

Api Design

Language

Apex

Description

Reports a method whose parameter list contains two or more Boolean parameters.

Rationale

Apex has no named arguments, so a call reads post(true, false) and says nothing about which flag is which. Two Boolean parameters of the same type sit next to each other with nothing to stop them being swapped, and a swapped pair compiles, deploys and silently does the opposite of what was meant. The reader is forced to open the declaration to understand any call site.

The following code illustrates the pattern detected by this rule:

public class BoolParams {

    // FLAGGED: Method declares two or more Boolean parameters
    public void post(Boolean draft, Boolean notify) {
        System.debug(draft);
    }

    // FLAGGED: Method declares two or more Boolean parameters
    public static void sync(Id recordId, Boolean force, String source, Boolean async) {
        System.debug(recordId);
    }

    public void postDraft(Boolean notify) {
        System.debug(notify);
    }

    public void update(Id recordId, String source) {
        System.debug(recordId);
    }
}

Remediation

Replace the flags with an enum or a small options class whose members are named at the call site, or split the method into the variants the flags select - postDraft() and postFinal() read better than post(true, false).

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved