Skip to content

[apex] New Rule: Invocable Classes require a no argument constructor #6793

Closed

Description

@FishOfPrey

Proposed Rule Name: InvocableClassNoArgConstructor

Proposed Category: Error Prone

Description:
Apex classes that declare @InvocableVariable fields or properties must expose an
accessible no-argument constructor. Salesforce Flow instantiates these classes via a
zero-arg constructor. When a developer adds any explicit constructor, Apex no longer
synthesises a default one, so Flow cannot create an instance and throws a runtime error. E.g. System.TypeException: MyInvocableClass does not have a no-arg constructor.

Global classes have an additional requirement: the no-arg constructor must be global
so that it remains accessible from managed packages.

Summer '26 Release Note: Provide Visible No-Argument Constructors for Custom Apex Classes Used as Invocable Action Parameters

Code Sample:

// BAD: explicit constructor eliminates the default constructor;
// Flow cannot instantiate this class at runtime
public class FlowInput {
    @InvocableVariable
    public String recordId;

    public FlowInput(String recordId) {
        this.recordId = recordId;
    }
}

// BAD (global class): no-arg constructor is not global;
// cross-package Flows cannot instantiate this class
global class FlowInput {
    @InvocableVariable
    global String recordId;

    private FlowInput() {}

    public FlowInput(String recordId) {
        this.recordId = recordId;
    }
}

// GOOD: explicit no-arg constructor restores Flow compatibility
public class FlowInput {
    @InvocableVariable
    public String recordId;

    public FlowInput() {}

    public FlowInput(String recordId) {
        this.recordId = recordId;
    }
}

// GOOD (global class): global no-arg constructor is accessible from managed packages
global class FlowInput {
    @InvocableVariable
    global String recordId;

    global FlowInput() {}

    global FlowInput(String recordId) {
        this.recordId = recordId;
    }
}

Possible Properties:

No — the rule has a single clear failure condition (missing accessible no-arg constructor) with no thresholds or configurable behaviour warranted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:new-rule

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions