Class declares more than one @InvocableMethod

ID

apex.correctness.invocablemethod_one_per_class

Severity

high

Remediation Complexity

medium

Remediation Risk

medium

Remediation Effort

medium

Resource

Api Design

Language

Apex

Description

Reports a class declaring two or more methods annotated @InvocableMethod.

Rationale

The platform allows exactly one @InvocableMethod per class, and it rejects the class that breaks the rule. The error is a compile error, so it does not appear when the second action is written but when the metadata is saved or deployed, and it stops the whole deployment rather than the one class. In a package or a release pipeline that means a failed promotion for a mistake that a second class would have avoided, and a Flow that referenced the first action keeps working only because the change never landed.

The following code illustrates the pattern detected by this rule:

// FLAGGED: Class declares more than one @InvocableMethod
public class AccountFlowActions {

    @InvocableMethod(label='Archive Accounts' description='Marks the accounts as archived')
    public static List<Id> archive(List<Id> accountIds) {
        return accountIds;
    }

    @InvocableMethod(label='Restore Accounts' description='Clears the archived flag')
    public static List<Id> restore(List<Id> accountIds) {
        return accountIds;
    }
}

Remediation

Keep one @InvocableMethod per class and move the other actions into their own classes, each named after the action it exposes to Flow. Where the actions share logic, leave that logic in a plain service class and let each invocable class be a thin wrapper over it.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved